静态块的加载顺序
package HomeWork4_14.MyTest;
import HomeWork4_2.Zoo.Bird;
class X{
public static void main(String[] args) {
new B();
}
}
public class Test {
static {
System.out.println("A");
}
{
System.out.println("AC");
}
public Test(){
System.out.println("ACD");
}
}
class B extends Test{
static {
System.out.println("B");
}
{
System.out.println("BC");
}
public B(){
System.out.println("BCD");
}
}
最后输出结果时
A
B
AC
ACD
BC
BCD
先执行静态块的加载,然后调用父类的实例化块和构造方法,然后子类的实例化块和构造方法