Unit 3 Cycle 2 Day 28: Polymorphic Array

Unit 3, Classes & Objects • Cycle 2
Day 28 Advanced Practice • Harder Difficulty
Focus: Polymorphic Array Hard Polymorphic Array

Advanced Practice Question

Format: Polymorphic Array

What is the output?
public class Shape {
    public void draw() {
        System.out.print("S");
    }
}

public class Circle extends Shape {
    public void draw() {
        System.out.print("C");
    }
}

// In another class:
Shape[] shapes = new Shape[2];
shapes[0] = new Shape();
shapes[1] = new Circle();

for (Shape s : shapes) {
    s.draw();
}
Difficulty: Hard  |  Topic: Polymorphic Array  |  Cycle: 2 (Advanced)
Why This Answer?

shapes[0] is a Shape object → draws S. shapes[1] is a Circle object → draws C (polymorphic behavior). Output: SC.

Common Mistake
Watch Out!

Thinking the array type determines which draw() is called.

AP Exam Strategy

Runtime type of each object determines which overridden method executes.

Master This Topic

This Cycle 2 HARD question tests polymorphic array. Review Unit 3 concepts to build mastery of classes & objects.

  • Understanding polymorphic array
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 3 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

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