This prints out r1 r4 pre b1 b2 r3 r2 hawk
But I don't understand why it prints r3 r2 instead of r2 r3 which seems backwards. If the initialization blocks execute top down, why does it begin with the bottom statement r3 and finish with r2? In the superclass Bird it executes as I would expect with b1 and b2, top to bottom, but in the superclass Raptor, after the constructor runs, control seems to jump to the last statement first and work itself back toward the top. Any ideas?
It's driving me crazy.
class Bird {
{ System.out.print("b1 "); }
public Bird()
{ System.out.print("b2 ");
}
class Raptor extends Bird {
static { System.out.print("r1 "); }
public Raptor()
{System.out.print("r2 "); } // don't these two print backwards?
{System.out.print("r3 "); } // ???
static { System.out.print("r4 "); }
}
class Hawk extends Raptor {
public static void main(String[] args) {
System.out.print("pre ");
new Hawk();
System.out.println("hawk ");
}
}