I have a parent class and extended class, both contain a toString()
method.
How would I go about calling the parent class's toString()
method from the Test app?
Right now to call the extended class's toString method it's objectname.toString()
, but what about the parent class?
Thanks in advance for the help.
You can't. This is called polymorphism, and that's what OOP is all about. The subclass toString redefines (overrides) the parent toString method.
If you want to be able to call the parent one, you need to add another method, with another name:
@Override
public String toString() {
// redefine the toString method
}
public String parentToString() {
return super.toString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With