Directly, no. To give access to the superclass implementation, you have to expose it somehow, otherwise it it is not visible externally at all. There are a couple ways you can do this.
Child Method Calling Super
You could add a method to Child
that calls Parent
's implementation of display()
:
public void superDisplay()
{
super.display();
}
You would have to cast your reference to make the call:
((Child)parent).superDisplay();
Note that adding a method to Parent
that calls display()
would not help because it would call Child.display()
for Child
instances because of polymorphism.
Something similar to this technique is commonly used when extending swing components, where the child's implementation of paintComponent()
often invokes super.paintComponent()
.
Reflection
While often a kludge indicating bad design, reflection will give you exactly what you want. Simply get the display
method of the Parent
class and invoke it on a Child
instance:
try {
Parent.class.getMethod("display").invoke(parent);
} catch(SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | ex) {
// oops!
}