- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorsInInheritance.java
More file actions
Latest commit
38 lines (36 loc) · 1.09 KB
/
Copy pathConstructorsInInheritance.java
File metadata and controls
38 lines (36 loc) · 1.09 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
classBase1{
Base1(){
System.out.println("I am a constructor");
}
Base1(intx){
System.out.println("I am an overloaded constructor with value of x as: " + x);
}
}
classDerived1extendsBase1{
Derived1(){
//super(0);
System.out.println("I am a derived class constructor");
}
Derived1(intx, inty){
super(x);
System.out.println("I am an overloaded constructor of Derived with value of y as: " + y);
}
}
classChildOfDerivedextendsDerived1{
ChildOfDerived(){
System.out.println("I am a child of derived constructor");
}
ChildOfDerived(intx, inty, intz){
super(x, y);
System.out.println("I am an overloaded constructor of Derived with value of z as: " + z);
}
}
publicclassConstructorsInInheritance {
publicstaticvoidmain(String[] args) {
// Base1 b = new Base1();
// Derived1 d = new Derived1();
// Derived1 d = new Derived1(14, 9);
// ChildOfDerived cd = new ChildOfDerived();
ChildOfDerivedcd = newChildOfDerived(12, 13, 15);
}
}