Public class testStatic extends Fa {static {System. out. println ("son: static code block") ;}{ System. out. println ("son: constructing code blocks");} public testStatic () {System. out. println ("son: constructor block");} public testStatic (String s) {super (s); System. out. println ("son: constructor block" + s);} public static void main (String [] args) {testStatic te; System. out. println (); Fa t = new testStatic ("ai") ;}} class Fa {static {System. out. println ("fa: static code block") ;}{ System. out. println ("fa: constructing code blocks");} public Fa () {System. out. println ("fa: constructor block");} public Fa (String s) {System. out. println ("fa: constructor block" + s );}}
Output result: ================== fa: static code block son: static code block fa: constructor block aison: constructor: constructor block ai ==================== draw a conclusion: 1. execution sequence: static code> code block> constructor 2. the static code block is executed with the class declaration, while the Construction Code block and construction method are executed after a class is instantiated. The construction code block takes precedence over the construction method 3. when the subclass testStatic does not use super (s), the output is the fa: constructor block by default, which calls the non-parameter constructor of fa.