[student notes] initialization order

I. the order in which initialization is not inherited

Static variables, static blocks, constructors, variables

Package test; / / no inheritance under the code public class test5 private static String {/ / static variable st= "static"; / / static{System.out.println static block (st); System.out.println ("static"); / / {System.out.println} block (block); / / private String st2=} constant "variables"; test5 (System.out.println) {/ / constructor (ST2); System.out.println ("constructor");} public static void main (String[] args) {new}} (test5);

The output of the code is:
static variables,
static blocks,
blocks,
variables,
constructors

From this you can get the initialization order without inheritance.

Two when initialization exists, initialization follows

Enter your content here, be careful not to use the backspace key to delete all the text, please keep one or select the mouse to enter directly to prevent confusion.

Package test; / / public class TEST6 extends subclass code test5 private static String {/ / static variable st= "static variables"; / / static{System.out.println static block (st); System.out.println ("static"); / / {System.out.println} block ("subclass");} / / private String. St2= "sub class variables" (TEST6); / / constructor {System.out.println (ST2); System.out.println ("subclass constructor");} public static void main (String[] args) {new}} (TEST6); / / test / / package superclass code; no inheritance under the code public class test5 {/ / static private static String st= variable parent static variable The amount of "; / / static block static{System.out.println (st); System.out.println (" superclass static block ");} / / block {System.out.println (" parent "); / / private String st2=} constant" parent variables "; / / constructor test5 () {System.out.println (ST2); System.out.println (" the parent class constructor "}});

Print results:
superclass static variable
superclass static block subclass
subclass
static variable static block
block
parent parent class variable
superclass constructor is a subclass of
block
subclass
subclass constructor variables

Thus, from the statement I printed, it is obvious that the initialization order exists at the time of inheritance.

Pay attention to our study together,

[student notes] initialization order
cicadas Hall