Class Helloa {
Public Helloa () {
System.out.println ("Helloa");
}
{System.out.println ("I ' M A class");}
static {System.out.println ("static A");}
}
public class Hellob extends Helloa {
Public Hellob () {
System.out.println ("Hellob");
}
{System.out.println ("I ' M B class");}
static {System.out.println ("static B");}
public static void Main (string[] args) {
System.out.println ("Main () Start");
New Hellob ();
System.out.println ("Main () end");
}
}
The result of the operation is:
Static A
Static B
Main () Start
I ' M A class
Helloa
I ' M B class
Hellob
Main () End
Object Initialization Order: (1) After the class is loaded, the static modified statement is executed from top to bottom (from parent to subclass), (2) when the static statement is executed, then the main method is executed, and (3) If the statement new has its own object, the construction code block is executed from top to bottom, Constructors (both of which can be said to be bound together).
Initialization order of objects in Java