-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperThisChild.java
More file actions
40 lines (31 loc) · 1007 Bytes
/
Copy pathSuperThisChild.java
File metadata and controls
40 lines (31 loc) · 1007 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
37
38
39
40
public class SuperThisChild extends SuperThisParent {
public static void main(String[] args) {
new SuperThisChild();
new SuperThisChild(1);
new SuperThisChild("parent");
}
String parent = "name1";
SuperThisChild() {
System.out.println("Constructor SuperThisChild() runs.");
}
SuperThisChild(int number) {
this(); // this constructor
System.out.println("Constructor SuperThisChild(int " + number + ") runs.");
}
SuperThisChild(String parent) {
super("name2"); // super constructor
System.out.println("Constructor SuperThisChild(String " + parent + ") runs.");
System.out.println("parent (old value)=" + this.parent); // this variable
this.parent = super.title; // super variable
System.out.println("parent (new value)=" + this.parent);
}
}
class SuperThisParent {
String title = "title";
SuperThisParent(String name) {
System.out.println("Constructor SuperThisParent( String " + name + ") runs.");
this.title = name; // this variable
}
SuperThisParent() {
}
}