Unit 3 Cycle 2 Day 10: Abstract Thinking: What Should Be Overridden

Unit 3 Advanced (Cycle 2) Day 10 of 28 Advanced

Abstract Thinking: What Should Be Overridden

Section 3.13 — Overriding Methods

Key Concept

Deciding which methods to override in a subclass requires understanding the superclass contract and the subclass specialization. A method should be overridden when the subclass needs different behavior than the default. Methods that should typically be overridden include toString() (for meaningful output), equals() (for value comparison), and any behavior method where the subclass acts differently. The AP exam tests this conceptually by asking which methods in a hierarchy should be overridden to achieve specific behavior.

Consider the following class hierarchy.

public class Shape { public double area() { return 0; } public String toString() { return "Shape"; } } public class Rectangle extends Shape { private double w, h; public Rectangle(double w, double h) { this.w = w; this.h = h; } public double area() { return w * h; } }

What does System.out.println(new Rectangle(3, 4)); print?

Answer: (A) Shape

Rectangle does NOT override toString(). It inherits Shape's version, which returns "Shape". The area() method is overridden but toString() is not.

Why Not the Others?

(B) println calls toString(), not area(). toString() returns "Shape".

(C) Shape overrides Object's toString(), so the default hash format is not used.

(D) toString() does not return the dimensions.

Common Mistake

Overriding one method does not affect others. Rectangle overrides area() but not toString(). Each method must be overridden independently.

AP Exam Tip

Check which methods are overridden in the subclass. If toString() is not overridden, the inherited version runs. Do not assume all methods are overridden.

Review this topic: Section 3.13 — Overriding Methods • Unit 3 Study Guide

More Practice

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.