forked from singh-anant/HacktoberFest22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWH_42_Constructors.java
56 lines (48 loc) · 1.4 KB
/
CWH_42_Constructors.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
44
45
46
47
48
49
50
51
52
53
54
55
56
class MyMainEmployee{
private int id;
private String name;
public MyMainEmployee(){ // CONSTRUCTOR // CONSTRUCTOR OVERLOADING
id = 0;
name = "Abhi G";
}
/*
public MyMainEmployee(String myName){ // CONSTRUCTOR taking Argument
id = 45;
name = myName;
}
*/
public MyMainEmployee(String myName, int myId){ // CONSTRUCTOR taking 2 Argument
id = myId;
name = myName;
}
public MyMainEmployee(String myName){ // CONSTRUCTOR OVERLOADING
id = 1;
name = myName;
}
public String getName(){
return name;
}
public void setName(String n){
// name = n; //or
this.name = n;
}
public void setId(int i){
id=i; //or
// this.id = i;
}
public int getId(){
return id;
}
}
public class CWH_42_Constructors {
public static void main(String[] args) {
// MyMainEmployee abhi = new MyMainEmployee();
// MyMainEmployee abhi = new MyMainEmployee("Abhi Gupta"); // Passing Argument
// MyMainEmployee abhi = new MyMainEmployee("Abhi Gupta", 12); // Passing 2 Argument
MyMainEmployee abhi = new MyMainEmployee();
// abhi.setName("Abhi G");
// abhi.setId(34);
System.out.println(abhi.getId());
System.out.println(abhi.getName());
}
}