Well first ChildExtending
needs to be initialized (as a type). That will produce the output of
parent static executed
child static block executed
as per section 12.4.2 of the JLS.
Only once the type is initialized can the constructor be called, at which point you'll get the output of:
parentAbstract initialized
child const initialized
And once the object is constructed, you can call an instance method on it, with output of:
MethodInParent called
I think the piece you're missing is that the type has to be completely initialized before the constructor starts. The constructor call can't initialize just enough of the superclass to call its constructor, then initialize the subclass. Aside from anything else, if you call getClass()
in the superclass constructor, that has to be a fully initialized class - which has to be the subclass, because that's what the object is an instance of.