Hello evry body ,
i have find this code on a mock exam :
*********************
class Bird {
{ System.out.print("b1 "); }
public Bird() { System.out.print("b2 "); }
}
class Rapace extends Bird {
static { System.out.print("r1 "); }
public Rapace() { System.out.print("r2 "); }
{ System.out.print("r3 "); }
static { System.out.print("r4 "); }
}
class Eagle extends Rapace {
public static void main(
String[] args) {
System.out.print("pre ");
new Eagle ();
System.out.println("eagle ");
}
}
**********************
The code compiles fine and gives the output :
r1 r4 pre b1 b2 r3 r2 eagle
I can't understand how !
Can someone explain what happens at execution time, what is first loaded ?.. to have this order in the output.
Many thanks by advance