-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorOverload.java
More file actions
36 lines (31 loc) · 942 Bytes
/
Copy pathConstructorOverload.java
File metadata and controls
36 lines (31 loc) · 942 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
public class ConstructorOverload {
int x;
ConstructorOverload() {
System.out.println("Inside MyClass().");
x = 0;
}
ConstructorOverload(int i) {
System.out.println("Inside MyClass(int).");
x = i;
}
ConstructorOverload(double d) {
System.out.println("Inside MyClass(double).");
x = (int) d;
}
ConstructorOverload(int i, int j) {
System.out.println("Inside MyClass(int, int).");
x = i * j;
}
}
class OverloadConsDemo {
public static void main(String[] args) {
var t1 = new ConstructorOverload();
var t2 = new ConstructorOverload(88);
var t3 = new ConstructorOverload(17.23);
var t4 = new ConstructorOverload(2, 4);
System.out.println("t1.x: " + t1.x);
System.out.println("t2.x: " + t2.x);
System.out.println("t3.x: " + t3.x);
System.out.println("t4.x: " + t4.x);
}
}