public class TestA { public static void main(String []args) { new B(); } } class A { static { System.out.println("static A"); } public A() { System.out.println("constutor A"); } { System.out.println("normal A"); } } class B extends A{ static { System.out.println("static B"); } { System.out.println("normal B"); } public B() { System.out.println("constutor B"); } }
结果
static A
static B
normal A
constutor A
normal B
constutor B
结论,父类静态--》子类静态--》父类初始化=父类代码块--》父类构造函数--》子类代码块=子类初始化--》子类构造函数