this topic is described in jls. here is my understanding:
1.initialize the superclass's class.( recursively. same to 2-3 )
2.if the class has not loaded. find it and load it. allocate the enough memory. fill the memory with 0.
so at this time, its class members are defined with default value (binary 0).
3.excute the class initialization. such as static member initialization and static block.
4.initialize the superclass's instance.(recursively. same as 6-7)
5.call the super's constructor. if there is a super(aaa) call in the sub's constructor, it will call the specified constructor. otherwise call the default one. (recursively)
6.initialize the instance. allocate the memory. fill the memory with 0. so the instance members are defined with default value.
7.excute the instance initialization. such as intance member's initialization and the instance initialization block.
8.call the specified constructor.
these codes will helo u:
<code><pre>public class Outer extends Base
{
static
{
System.out.println("Outer static initialization");
}
{
System.out.println("Outer instance initialization");
}
public Outer()
{
System.out.println("Outer construction");
}
public Outer(int i)
{
super(i);
System.out.println("Outer construction with "+i);
}
public static void main(
String[] args) {
new Outer();
System.out.println("\n ===== \n");
new Outer(4);
}
}
class Base
{
static
{
System.out.println("base static initialization");
}
{
System.out.println("base instance initialization");
}
public Base()
{
System.out.println("base construction");
}
public Base(int i)
{
System.out.println("base construction with "+i);
}
};</pre></code>