My study guide says "Static init blocks are executed at class loading time"
Based on C extends B, B extends A and new C() is invoked my thought is class C should be loaded first before the call within C's constructor to super() which is B's constructor, then before B's constructor runs, B class is loaded, etc.
Thus I would choose CBA... according to my understanding of the class loading time, unless A loads before B, B loads before C, are there any references talks about this?
Originally posted by Jacky Zhang: My study guide says "Static init blocks are executed at class loading time" ...
It's probably more accurate to say that static blocks are executed when the class is "initialized" -- rather than "loaded." So the question here is really about order of initialization.
JLS 12.4 - Initialization of Classes and Interfaces states, "Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables)... Before a class is initialized, its superclass must be initialized..." This particular scenario is illustrated under 12.4.1.
In general, initialization must occur from the top downward in an inheritance hierarchy so that the superclass can be used by the subclass.