Actually, I came across a similar problem in Enthuware, applied the same logic, and got the answer wrong:
What will be output when class
Test is run:
My answer was:
It will print one, super and two
1. When the reference variable of type One is declared, its static blocks are initialized, i.e
static { System.out.print("one "); }
will print "one"
2. When reference variable of type Two is declared and instance of Two is created on the heap, i.e.
Two t = new Two();
Super's static block will execute, outputting "super"
3. Then Two's static block will execute, outputting "two"
Yet, my answer is wrong....
The explanation is
"one" will not be printed as class One is not actively used.
Which leaves
It will print super and two.
Please explain!!!