posted 16 years ago
r1 r4 pre b1 b2 r3 r2 hawk
Whenever a class is loaded, all the static initialiser blocks are excuted.
Next when you create an object of the class, first of all the instance initialiser blocks are executed and then constructor runs. At the time of running constructor, the implicit super() call to superclass consctrucor is invoked.
So when the classes are loaded "r1" and "r4' get printed, then at main method -> print "pre" . Then implicit constructor of Hawk calls super() to run Raptor(), which in turn calls Bird(). Before creating Bird object, the instance initialiser block is executed and "b1" gets printed. Then constructor runs and "b2" gets printed. It comes back to Raptor constructor where instance initialiser block gets excuted and "r3" is printed, then "r2" and finally "hawk" in main.