public class Person {
public Person(int id) {
System.out.println("person(" + id + ")");
}
public static void main(String[] args) {
Build b = new Build();
}
}
class Build {
Person p1 = new Person(1);
public Build() {
System.out.println("this is build's block!");
Person p2 = new Person(2);
}
Person p3 = new Person(3);
}
为什么输出的是这个?
person(1)
person(3)
this is build's block!
person(2)
main方法 第一句是 Build b = new Build();
应该先执行 Build的无参构造方法啊 |
|