-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathConstructorChain.java
More file actions
86 lines (82 loc) · 1.53 KB
/
ConstructorChain.java
File metadata and controls
86 lines (82 loc) · 1.53 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*WeakerAccess Rule
CoVariant Return type
*/
class Parent
{
final int MIN_AGE;
int x=20,y;
void print(){
final int P;
if(x>2){
P=100;
}
else{
P=999;
}
System.out.println("Print Call of Parent "+P);
}
void display(){
System.out.println("Display call of parent");
}
void show(){
System.out.println("Parent Show call");
}
Parent(){
MIN_AGE=18;
System.out.println("Parent class Default cons call");
//x = 1200;
y = 2000;
}
Parent(int x, int y){
this();
System.out.println("Parent class Param cons call");
this.x = x;
this.y = y;
}
}
class Child extends Parent
{
int x =1;
int y = 2222;
int z;
void output(){
System.out.println("Child class output call");
}
@Override
void print(){
System.out.println("Child Print Call");
}
@Override
void show(){
super.show();
System.out.println("Child Show Call");
}
Child(){
//super(10,20);
// super(); // this will calll parent class default cons
z = 300 + this.x+ super.x + y;
System.out.println("Child class default cons call"+z);
}
Child(int z ){
//this();
//super(100,200);
this.z = z + x + y;
System.out.println("Child Class Param Cons Call "+this.z);
}
}
public class ConstructorChain {
public static void main(String[] args) {
// TODO Auto-generated method stub
Parent child = new Child();
child.show();
child.print();
child.display();
//child.output();
System.out.println(child.x+" "+child.y);
//child.print();
final int P = 90;
final Child child2 = new Child();
child2.x++;
//child2 = new Child();
}
}