If A extends B
, using IntelliJ
idea, how can i generate toString()
using B's public (or protected) methods automatically.
In this example, how can i include public methods from the FileRow?
In a subclass, toString() can call the superclass toString() method using super. toString() and then add on its own attributes. In the following code, the Person class overrides the Object toString() method and the Student class overrides the Person toString() method. They each add on their attributes.
super keyword is used to call parent class methods in case of inheritance. Every class is the child of Object class in java and one of its non-final methods is toString() . So super. toString() calls Object class method toString() .
The toString method is used to return a string representation of an object. If any object is printed, the toString() method is internally invoked by the java compiler. Else, the user implemented or overridden toString() method is called.
There is a template to use super.toString()
, but there is no way to reference superclass members directly. It may be worth submitting a new request for this feature.
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