The output "r1 r4 pre b1 b2 r3 r2 hawk" is described below:
1. Class Hawk and all its parent classes are loaded into memory. As soon as it loads up all static initialization blocks are executed. This explains "r1" and "r4".
2. The main method is executed next. This prints "pre".
3. You create an instance of Hawk. As Hawk extends from Raptor and Raptor from Bird, the Hawk constructor needs to initialize both Bird and Raptor in the same order. This prints "b1" "b2" "r3" and "r4".
4. Finally, the last statement in main is executed. This prints "hawk".
Hope this helps! Any queries, get back to me.
Joined: Aug 12, 2009
Thanks Jaydeep and Akanksha.
I was confused about the order of "pre" rest for rest I was sure for their occurence in the output.