1 classB {2 3 PublicB () {4 Super();5System.out.println ("Constructor B");6 }7 {8System.out.println ("Normal code block B");9 }Ten Static{ OneSystem.out.println ("Static code block B"); A } - - } the Public classClassAextendsB { - - PublicClassA () { - Super(); +System.out.println ("Constructor a"); - } + { ASystem.out.println ("Normal code block a"); at } - Static{ -System.out.println ("Static code block a"); - } - Public Static voidMain (string[] args) { -ClassA a=NewClassA (); in } -}
The results of the operation are as follows:
Static code block B
Static code block A
Common code block B
Constructor b
Common code block A
Constructor a
can see The static code block is executed first, then the normal code block of the parent class, the parent class constructor, and then the generic code block of the subclass, the subclass constructor
java--Common code block static code block execution order