This is one for the theorists :
Very simple :
I have two classes, Top and Bottom
Bottom is a subclass of Top
Bottom overrides the method int foo()
BUT ! in the parent, int foo() has
default access (package)
in the subclass I have it public int foo() with
public access
now..I have the class Goof :
Goof is in the same package as Top,
now the overridden function foo() is defined not by the
class of the reference variable, but from the class Bottom in
this case.
Right?
So I should see
top 20 the Bottom class definition of foo()
and
bottom 20 the Bottom class definition of foo()
Right? That's what polymorphism says.
however with Goof.class in the same package /top
I get :
top 10
bottom 20
default access of the int foo() in Top class makes
polymorphism no longer valid.
Right?