publicclassMain{ publicstaticvoidmain(String... args){ new Out("Main start\n"); new Out("Before new a B object"); new Out(); new B(); new Out(); new Out("After new a B object"); new Out(""); new Out(); new Out(C.constCvar); new Out(); new Out(C.staticCVar); new Out(); new Out("Before new a C object"); new Out(); new C(); new Out(); new Out("After new a C object"); new Out(""); new Out("Main end"); } }
Before new a B object ------------------------- A static member o1 initialize A static block execute B static member o3 initialize B static block execute A member o2 initialize A non-static block execute A constructor execute B member o4 initialize B non-static block execute B constructor execute ------------------------- After new a B object
------------------------- const C member ------------------------- C static block execute static C member ------------------------- Before new a C object ------------------------- C constructor execute ------------------------- After new a C object