public class b{public static B t1 = new B (); public static B t2 = new B (); {System.out.println ("building Block"); } static {System.out.println ("static Block"); } public static void Main (string[] args) {b t = new B (); }}
Correct answer building block construction block static block construction block
static block: With static declaration, the JVM executes when the class is loaded, executes only one construction block: The class is defined directly with the {}, execution order priority is executed each time the object is created: static block > Main () > Construction block > Construction method static blocks are executed in the order of declaration, so the PUBLICSTATICB T1 =&NBSP;NEWB () is executed first, the statement creates the object, and the construction block is called, and the output construction block is then executed Public static B T1 = new < Span style= "Color:rgb (51,51,51)" > B (); output building block re-execution static{system.out.println ("static Block");} Output static block the last Main method executes, creates the object, and outputs the construction block.
copyright notice: This article for Bo Master original article, without Bo Master permission not reproduced.
Does Java static code block really take precedence?