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);
}
}
---------------------------------------------------------
结果:132
总结:子类的构造器中没有super();不管子类构造器中有无参数都会去调用父类的无参构造函数,若父类没有无参构造函数则会报错!
原文地址:https://www.cnblogs.com/2016-cxp/p/11005325.html
时间: 2024-11-09 00:40:51