01
Overview

Two subclasses, one superclass, polymorphic loop.

The classic AP scenario: a single array of superclass references holds multiple subclass objects — and one method call produces different results for each.

The full power of polymorphism appears when two or more subclasses share a parent and one piece of client code processes all of them uniformly. The array holds them as the parent type; each call dispatches to the right override.

This is the foundation of the AP CSA "hierarchy of shapes / vehicles / animals" FRQ pattern — and the cleanest demonstration of why polymorphism matters.

On the AP exam, this appears in MCQs about dispatch and in FRQs that ask you to write a generic processing loop over a mixed array.

02
Core Concept

An array of the parent type; the right method runs per object.

No instanceof checks needed.

Setup

public class Shape {
    public double area() { return 0; }
}

public class Circle extends Shape {
    private double r;
    public Circle(double r) { this.r = r; }
    @Override public double area() { return Math.PI * r * r; }
}

public class Square extends Shape {
    private double s;
    public Square(double s) { this.s = s; }
    @Override public double area() { return s * s; }
}

The polymorphic processor

public static double totalArea(Shape[] shapes) {
    double total = 0;
    for (Shape sh : shapes) {
        total += sh.area();
    }
    return total;
}

One loop. Each iteration calls area(), but the actual computation depends on the object's class.

Why no instanceof?

Polymorphism eliminates the need for explicit type checks. As long as every subclass overrides area(), the loop handles any new subclass added later without modification.

03
Key Vocabulary

Multi-subclass vocabulary.

The terms of polymorphic processing.

Vocabulary
  • Sibling subclasses — two classes that share the same parent.
  • Polymorphic collection — array or list of the parent type holding mixed subclass objects.
  • Uniform interface — the parent's method signatures, shared by all children.
  • Open for extension — adding a new subclass doesn't break existing code.
  • Dynamic dispatch — runtime method selection per object.
04
AP Exam Focus

How multi-subclass polymorphism is tested.

Loop dispatch and reference vs object dominate.

Exam Focus
  • Parent-typed array, mixed objects. Each call dispatches per object.
  • Same method name across subclasses. Enables uniform processing.
  • Total / max / count across types. Common FRQ patterns.
  • No instanceof needed. Polymorphism replaces type checks.
05
Worked Example

Total area of mixed shapes.

One loop; correct dispatch.

Worked Example AP-style reasoning

Input: { new Circle(2), new Square(3), new Circle(1) }.

Trace.

  • Circle(2).area() = π * 4 ≈ 12.566.
  • Square(3).area() = 9.
  • Circle(1).area() = π ≈ 3.142.

Total: ≈ 24.708.

Why this matters. If you added a Triangle class with its own area override, the same loop would handle it — no code change required.

06
Common Mistakes

Multi-subclass pitfalls.

Most write code that defeats polymorphism.

Watch Out
  • Using instanceof to pick which area to compute. Defeats polymorphism.
  • Casting unnecessarily. ((Circle) sh).area() is needless when Shape declares area.
  • Forgetting to override in a subclass. That subclass uses parent's placeholder.
  • Holding objects as subclass type when parent suffices. Limits reuse.
07
Reference Table

Polymorphic processor.

Three requirements.

Multi-Subclass Reference

AP Quick Reference
RequirementDetailAP Tip
Common parentBoth subclasses extend itDefines the method.
Override in eachSubclass-specific logicSignature matches.
Parent-typed arrayHolds mixed objectsPolymorphic processing.
Single loopCalls the shared methodDispatch handles the rest.
08
Practice Tip

How to master multi-subclass polymorphism.

Trust dispatch; avoid type checks.

Practice Strategy
  • MCQ Practice — for each loop, trace the dispatch per object before computing the total.
  • Java Lab — build Shape/Circle/Square/Triangle. Write totalArea and verify it handles all three.
  • FRQ Practice — write a polymorphic loop without instanceof. Add a third subclass after to confirm no changes are needed.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 08 Topic 09 Two Subclasses and Polymorphism Two Subclasses and Polymorphism FRQ Practice

AP-style topic practice assessment

Start