01
Overview

Polymorphism: one call, many behaviors.

The most powerful idea in object-oriented Java — and the source of the most-tested MCQs in inheritance units.

Polymorphism means a single piece of code can call a method on different types of objects and get different — but appropriate — behavior for each. The same line shape.area() produces a circle's area on a Circle and a square's area on a Square.

Java's mechanism: dynamic dispatch. The decision about which method runs is made at runtime, based on the actual object type — not the declared type of the reference.

On the AP exam, polymorphism MCQs are everywhere. Mastering them is essential for FRQ inheritance design too.

02
Core Concept

Declared type ≠ actual type.

Java dispatches by the object; the compiler checks by the reference.

Reference type vs object type

Shape s = new Circle(2);   // declared type Shape; actual type Circle
double a = s.area();       // calls Circle.area() — actual type wins

The compiler vs the runtime

  • Compile time: Java checks that the reference's declared type has the method. If Shape doesn't declare area, this is a compile error.
  • Runtime: Java picks the version based on the actual object.

Polymorphic collection

Shape[] shapes = { new Circle(2), new Square(3), new Circle(5) };
for (Shape s : shapes) {
    System.out.println(s.area());   // each shape uses its own formula
}

One loop; three different computations — that's polymorphism.

Limits

You can only call methods declared in the reference type. If Circle has a method getRadius() not in Shape, then s.getRadius() won't compile.

03
Key Vocabulary

Polymorphism vocabulary.

The exact terms AP uses.

Vocabulary
  • Polymorphism — one interface, multiple implementations.
  • Dynamic dispatch — runtime method selection.
  • Declared type — the reference variable's type.
  • Actual type — the object's class (created with new).
  • Static binding — compiler's method check.
  • Late binding — runtime decides.
  • Upcasting — treating a subclass as its superclass type.
04
AP Exam Focus

How polymorphism is tested.

Reference vs object distinction is the dominant trap.

Exam Focus
  • Method dispatch is by actual object. Period.
  • Compile checks against declared type. Can't call methods not declared in the reference type.
  • Casting can give access. ((Circle) s).getRadius() if you're sure of the type.
  • Field access is not polymorphic. Fields are resolved by declared type — but AP fields are private, so this rarely matters.
05
Worked Example

Trace polymorphic calls.

Same line, different behavior.

Worked Example AP-style reasoning

Setup. Animal has speak() returning "Generic sound". Dog overrides to "Bark". Cat overrides to "Meow".

Animal a1 = new Animal();
Animal a2 = new Dog();
Animal a3 = new Cat();
Dog    d  = new Dog();

System.out.println(a1.speak());
System.out.println(a2.speak());
System.out.println(a3.speak());
System.out.println(d.speak());

Trace.

  • a1 (Animal): "Generic sound".
  • a2 (Dog held as Animal): "Bark" — actual type wins.
  • a3 (Cat held as Animal): "Meow".
  • d (Dog): "Bark".

Why this matters. a2's declared type is Animal, but Java picks Dog's speak because that's the actual object.

06
Common Mistakes

Polymorphism pitfalls.

Most assume the wrong dispatch rule.

Watch Out
  • Assuming declared type drives dispatch. It drives compile-time checks; actual type drives runtime dispatch.
  • Calling a subclass-only method on a superclass reference. Compile error without a cast.
  • Casting to the wrong type. ClassCastException at runtime.
  • Expecting fields to be polymorphic. They aren't.
07
Reference Table

Polymorphism rules.

Compile vs runtime.

Polymorphism Reference

AP Quick Reference
AspectRuleType used
Method exists checkCompile timeDeclared type.
Which method runsRuntimeActual type.
Field accessCompile timeDeclared type.
Cast safetyRuntimeActual type.
08
Practice Tip

How to master polymorphism.

Two questions: "does it compile?" and "what runs?"

Practice Strategy
  • MCQ Practice — first check compile (declared type). Then check dispatch (actual type).
  • Java Lab — build Animal/Dog/Cat. Hold each in an Animal reference and call speak.
  • FRQ Practice — write polymorphic loops; rely on dispatch to handle different types.
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 07 Overriding and Polymorphism FRQ Practice

AP-style topic practice assessment

Start