You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Classes with a super class should call super.toString() in their own toString implementation.
Example:
classPerson {
Stringname;
publicStringtoString() {
StringBuilderbuilder = newStringBuilder();
builder.append(' ').append(this.name);
returnbuilder.substring(1);
}
}
classStudentextendsPerson {
intstudID;
publicStringtoString() {
StringBuilderbuilder = newStringBuilder(super.toString()); // <-- super callbuilder.append(' ').append(this.name);
returnbuilder.toString(); // not using substring(1), since the builder no starts with space
}
}
The text was updated successfully, but these errors were encountered:
Classes with a super class should call
super.toString()
in their owntoString
implementation.Example:
The text was updated successfully, but these errors were encountered: