Subclass the parent class constructor calls

class People {
String name;
public People() {
System.out.print(1);
}
public People(String name) {
System.out.print(2);
this.name = name;
}
}
class Child extends People {
People father;

public Child(String name) {
System.out.print(3);
this.name = name;
father = new People(name + ":F");
}
public Child() {
System.out.print(4);
}

}

---------------------------------------------------------

Results: 132

Summary: the constructor of the subclass is not super (); regardless of whether the sub-class constructor parameters are to call the no-argument constructor of the parent class, if the parent is not no-argument constructor will be given!

Guess you like

Origin www.cnblogs.com/2016-cxp/p/11005325.html