Take a look at the code below it's form K&B but slightly altered
class Main{
static{ System.out.print("Test ");}
{System.out.print("b1 ");}
public Main()
{ System.out.print("b2 ");}
}
class Main2 extends Main
{
static { System.out.print("r1 ");}
public Main2()
{ System.out.print("r2 ");}
{ System.out.print("r3 ");}
static {System.out.print("r4 ");}
}
class Main3 extends Main2
{
static { System.out.print(" In Main2 ");}
public static void main(
String [] args)
{
System.out.print("Pre ");
new Main3();
System.out.println("Hawk ");
}
}
GIVES OUTPUT AS FOLLOWS
Test r1 r4 In Main2 Pre b1 b2 r3 r2 Hawk
The K&B Book fails to mention an important point....the static initializers are called as per the call hierarchy....the one which is called the first is the one from the base class Main and then followed by Main2 and Main3 respectively...a point never mentioned in K&B