posted 15 years ago
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.