多态构造过程:
结果:132
public class TestChild {
public static void main(String[] args) {
new Child("mike");
}
}
class People{
private String name;
public People(){
System.out.println("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){
//默认调用父类的无参构造super(),--不管有没有声明super(), 如果显式的调用super(实参列表)那么不会调用父类无参构造
//这里省略了super()
System.out.print("3");
father = new People(name +" F");
}
public Child(){
System.out.print("4");
}
}