forked from ParthMurge/Java-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcwh_41_onstructors_Overloading.java
More file actions
54 lines (47 loc) · 1.13 KB
/
cwh_41_onstructors_Overloading.java
File metadata and controls
54 lines (47 loc) · 1.13 KB
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
package company;
import java.lang.String;
class Employee4
{
private int id;
private String name;
// constructors:
public Employee4(int i, String n)
{
id = i;
name = n;
}
public Employee4(String n)
{
name = n;
}
// getters & setters:
public void setName(String a)
{
this.name = a; // We can also write "name" as "this.name"
}
public void setId(int a)
{
id = a;
}
public String getName()
{
return name;
}
public int getId()
{
return this.id; // We can also write "id" as "this.id"
}
}
public class cwh_41_onstructors_Overloading
{
public static void main(String[] args)
{
// Constructors can be overloaded just like other methods in java.
// There can be more than two overloaded constructors.
Employee4 e = new Employee4(4, "Danny");
Employee4 em = new Employee4("Khaleesi");
System.out.println(e.getId());
System.out.println(e.getName());
System.out.println(em.getName());
}
}