一个java基础笔试题
有个笔试题,看了好久,没想明白,为什么是这个结果(主要是1为什么先打印出来)
21.下面是People和Child类的定义和构造方法,每个构造方法都输出编号。在执行new Child("mike")的时候都有哪些构造方法被顺序调用?请选择输出结果(d )
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); }
}
A、312 B、32
C、432 D、132