Given:
class Animal { //from w w w . j a va 2s . c o m { System.out.print("b1 "); } public Animal() { System.out.print("b2 "); } } class Fish extends Animal { static { System.out.print("r1 "); } public Fish() { System.out.print("r2 "); } { System.out.print("r3 "); } static { System.out.print("r4 "); } } class SmallFish extends Fish { public static void main(String[] args) { System.out.print("pre "); new SmallFish(); System.out.println("hawk "); } }
What is the result?
D is correct.
Static init blocks are executed at class loading time; instance init blocks run right after the call to super()
in a constructor.
When multiple init blocks of a single type occur in a class, they run in order, from the top down.