I would think this question has been asked before, but was not immediately able to find an answer.
Say, somehow, a Pet
reference is assigned a Dog
object:
Pet pet = new Dog();
If I write
pet.attackInvader();
The child class (Dog
)'s method is called by virtue that all functions in Java are virtual.
Is it possible to invoke Pet
's attackInvader()
instead?
(I know I can edit Dog
's method to call super
, but, in this case, assume I cannot change Dog
's implementation.)