Call Superclass Methods on Subclass Objects
In this section...
“Superclass Relation to Subclass” on page 5-25
“How to Call Superclass Methods” on page 5-25
“How to Call Superclass Constructor” on page 5-26
Superclass Relation to Subclass
Subclasses can override superclass methods to support the greater specialization defined
by the subclass. Because of the relationship that a subclass object is a superclass object,
it is often useful to call the superclass version of the method before executing the
specialized subclass code.
How to Call Superclass Methods
Subclass methods can call superclass methods if both methods have the same name.
From the subclass, reference the method name and superclass name with the @ symbol.
This diagram illustrates how to call the superMethod defined by MySuperClass.
Subclass object passed to
the superclass method
superMethod@MySuperClass(obj,superMethodArguments)
Superclass name
Superclass method
Arguments passed to the
superclass method
For example, a subclass can call a superclass disp method to implement the display of
the superclass part of the object. Then the subclass adds code to display the subclass part
of the object: