class parent {
parent() {
System.out.println("parent");
}
}
public class child extends parent {
{
System.out.println("non static block");
}
child() {
super();
System.out.println("idk");
}
public static void main(String[] args) {
new child();
}
}
parent
non static block
idk
我期待的输出为
non static block
parent
idk
为什么没有非静态块运行第一?
创建对象后,任何java程序中的第一次调用是class的Constructer。 Constructer将会调用它的超级Constructer。 –