Here is the order of initialization:
1)Super class's static blocks and static variable declaration & initialization(as per their order).
2)Sub class's static blocks and static variable declaration & initialization(as per their order).
3)Super class's non-static blocks and non-static variable declaration & initialization(as per their order).
4)Super class's constructor.
5)Sub class's non-static blocks and non-static variable declaration & initialization(as per their order).
6)Sub class's constructor.
The original code will not compile. The following will:
class A
{
public A()
{
System.out.println("AAA");
}
{System.out.println("456");}
}
public class B extends A
{
B()
{
this(12);
System.out.println("BBB");
}
B(int x)
{
System.out.println("CCC");
}
{System.out.println("123");}
public static void main(String[] args)
{
new B();
}
}
[This message has been edited by Peter
Java (edited September 11, 2001).]