Start by looking at a demo and then Summarize.
1 classx{2 StaticM m=NewM ();3Y y=NewY ();4 publicX () {5System.out.print ("X");6 }7 }8 classy{9 publicY () {TenSystem.out.print ("Y"); one } a } - - classm{ the publicM () { -System.out.print ("M"); - } - } + - classn{ + publicN () { aSystem.out.print ("N"); at } - } - - public classZextendsx{ - StaticN n=NewN (); -Y y=NewY (); in publicZ () { -System.out.print ("Z"); to } + public Static voidmain (string[] Args) { - NewZ (); the } *}
The following conclusions can be summed up in Java initialization through a single-step test and access to relevant Data:
1. Initialize static member variables and static code blocks in the parent class.
2. Initialize static member variables and static code blocks in Subclasses.
3. Initialize the normal member variables and code blocks of the parent class, and then execute the parent Class's constructor Method.
4. Initialize the normal member variable and code block of the subclass, and then execute the subclass constructor Method.
(original) Java Initialization process