-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCH_09_Constructors.java
More file actions
43 lines (39 loc) · 953 Bytes
/
Copy pathCH_09_Constructors.java
File metadata and controls
43 lines (39 loc) · 953 Bytes
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 mainMyEmployee{
private int id;
private String name;
public mainMyEmployee() {
id = 0; //We Can Do Uncomments Also
name = "Your_Name_Here";
}
public mainMyEmployee(String MyName,int MyId) {
name = MyName;
id =MyId;
}
public mainMyEmployee(String MyName) {
name = MyName;
id =1;
}
public String getName(){
return name;
}
public void setName(String n){
this.name=n; //or name=n
}
public int getId(){
return id;
}
public void setId(int x){
id =x;
}
}
public class CH_09_Constructors {
public static void main(String[] args) {
//mainMyEmployee atharva=new mainMyEmployee("Your name",888);
//mainMyEmployee atharva=new mainMyEmployee();
mainMyEmployee atharva=new mainMyEmployee("Atharva");
//atharva.setName("Atharva");
//atharva.setId(777);
System.out.println(atharva.getId());
System.out.println(atharva.getName());
}
}