A
(superclass) and B
(subclass) have a common variable x
.
Now we make object of class B
, referred by a
which is of type of class A
.
Since variables are not overridden, so the statement a.x
will always refer to data member of superclass.
private
, final
, and static
methods and variables use static binding and are bonded by compiler while overridden methods are bonded during runtime based upon type of runtime object.
“Perhaps the rare and simple pleasure of being seen for what one is compensates for the misery of being it.” ― Margaret Drabble |