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);
}
}this
---------------------------------------------------------spa
結果:132class
總結:子類的構造器中沒有super();無論子類構造器中有無參數都會去調用父類的無參構造函數,若父類沒有無參構造函數則會報錯!構造函數