This site requires JavaScript, please enable it in your browser!
Greenfoot back
MrBradley
MrBradley wrote ...

2 days ago

Interactively execute a base class's method

MrBradley MrBradley

2 days ago

#
Currently, when you interactively execute a method in a base class appears; and the sub class version is execute. Today is class I was trying to interactively demonstrate the what I expected to be "super.move(int)" (for example). Instead the sub-classed, overridden version was executed. Is there a way (via SHIFT-click, or similar) to have the base class version executed? Thanks
danpost danpost

2 days ago

#
MrBradley wrote...
Currently, when you interactively execute a method in a base class appears; and the sub class version is execute. Today is class I was trying to interactively demonstrate the what I expected to be "super.move(int)" (for example). Instead the sub-classed, overridden version was executed. Is there a way (via SHIFT-click, or similar) to have the base class version executed?
I do not believe so. Once a method is overridden in a subclass, any and all actors created from that subclass take on the new behavior that the overriding method affords. You could create another method in the subclass
public void basicMove(int distance)
{
    super.move(distance);
}
to allow the option of the non-overridden behavior. However, you would not be able to call it (in code) with the object referenced as the parent type. Basically, you demonstrated that it does not matter whether the object was referenced as its type or its parent type; either way, the overriding method is executed. That should be the point to pass to your students.
You need to login to post a reply.