Java accesses the static variables of the parent class, and the loading of the subclass is a problem.


console shows that ChildClass has been loaded, why not output c init

Jvm
Mar.14,2021

the static block of the java class is executed not in load, but in initialize, involving two cases, new an instance, or accessing static methods, you output .a variable in main and do not access the members of childClass, so you will not execute the static block of childClass, if you output ChildClass.b,.

Menu