The static resolution of a method is always based on the Reference
type.
The code
superClassWithSuperCons.staticMethod(); superClassWithSubCons.staticMethod(); subClassWithSubCons.staticMethod();
converted to this after compilation
SuperClass.staticMethod(); SuperClass.staticMethod(); SubClass.staticMethod();
By connecting to this, this is a call to the SuperClass
method, not a subclass method. So, you get the output of the SuperClass
method.
source share