-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tutorial10_Constructor.java
43 lines (36 loc) · 1.05 KB
/
Tutorial10_Constructor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Employee
{
public String name;
private int experience;
private int salary;
// default constructor //
public Employee(){
name = "no_name";
experience = -1;
salary = -1;
}
// overloaded constructors //
public Employee(String name, int experience){
this.name = name;
this.experience = experience;
salary = -1;
}
public Employee(String name, int experience, int salary){
this.name = name;
this.salary = salary;
this.experience = experience;
}
public void introduce(){
System.out.printf("Name is: %s, experience: %d, salary: %d.\n", name, experience, salary);
}
}
public class Tutorial10_Constructor {
public static void main(String[] args) {
Employee saurav = new Employee();
Employee nishant = new Employee("Nishant", 2);
Employee ravi = new Employee("Ravi", 2, 20000);
saurav.introduce();
nishant.introduce();
ravi.introduce();
}
}