静态代码块执行顺序测试:
A类:
public class A {
static{
System.out.println("static A");
}
{
System.out.println("not static A");
}
}
B类:
public class B extends A {
static{
System.out.println("static B");
}
{
System.out.println("not static B");
}
}
Demo:
public class Demo {
public static void main(String[] args) {
B b = new B();
}
}
结果:
static A
static B
not static A
not static B