Extending the superclass's String output.
The classic toString pattern: keep what the parent said, then append the subclass's own details.
One of the most common override forms in AP CSA is a toString() that extends the parent's text rather than replacing it. The subclass calls super.toString(), then concatenates its own information.
The same approach applies to any method returning a String — descriptions, summaries, labels — where the subclass should add detail without losing the parent's wording.
On the AP exam, this pattern appears in inheritance FRQs that ask for a hierarchical String representation.
Append the subclass's details to the parent's string.
Concatenation handles the combination.
The template
@Override
public String toString() {
return super.toString() + ", subclassField=" + subclassField;
}
Concrete example
public class Vehicle {
private String make;
public Vehicle(String m) { make = m; }
public String toString() {
return "Make: " + make;
}
}
public class Car extends Vehicle {
private int doors;
public Car(String m, int d) { super(m); doors = d; }
@Override
public String toString() {
return super.toString() + ", Doors: " + doors;
}
}
new Car("Toyota", 4).toString() returns "Make: Toyota, Doors: 4".
Hierarchical chains
If a class further extends Car (say, SportsCar), the chain continues:
@Override
public String toString() {
return super.toString() + ", Top Speed: " + topSpeed;
}
Each level adds its own piece. The full string reflects every ancestor.
String-extension vocabulary.
Used in hierarchical-output problems.
- toString — method returning a String representation of an object.
- Concatenation — joining Strings with
+. - Hierarchical output — string that reflects multiple inheritance levels.
- Append — adding to the end of an existing String.
- String chain — each level adds its piece.
How String-extending overrides are tested.
Calling super and exact format dominate.
- Use super.toString(). Don't duplicate parent's output.
- Match the format exactly. Punctuation and spacing count.
- Cast or call toString on fields if needed. But primitives auto-convert.
- Don't call
this.toString(). Recursion trap.
Three-level extension chain.
Trace each toString.
Setup. Vehicle → Car → SportsCar. Each toString appends.
Vehicle.toString(): "Make: Honda"
Car.toString(): super.toString() + ", Doors: 2" → "Make: Honda, Doors: 2"
SportsCar.toString(): super.toString() + ", Top Speed: 250" → "Make: Honda, Doors: 2, Top Speed: 250"
Why this matters. Each level extends the previous String. The chain naturally produces a complete description.
Output-extension pitfalls.
Format and recursion are the top issues.
- Duplicating the parent's text. Use super; don't copy.
- Missing comma or space. AP rubrics check format.
- Calling this.toString() instead of super. Infinite recursion.
- Putting the addition in the wrong place. Pre- vs post-append matters for readability.
Extending output at a glance.
Three pieces; one line.
Output Extension Reference
AP Quick Reference| Piece | Source | AP Tip |
|---|---|---|
| Parent text | super.toString() | Reuses parent logic. |
| Separator | Literal (e.g., ", ") | Match rubric format. |
| Subclass detail | Subclass fields | Via accessors or direct. |
How to master output extension.
Trace each level; format precisely.
- MCQ Practice — for each toString chain, write out each level's contribution before concatenating.
- Java Lab — build Vehicle/Car/SportsCar and verify the chained output matches expected format.
- FRQ Practice — copy the rubric's format exactly: comma, space, label.
Practice — attempt these now.
AP-style assessments aligned to this lesson. Time them.
AP CSA Unit 08 Topic 04 Overriding That Extends Superclass Output FRQ Practice
AP-style topic practice assessment