AP CSA Unit 3 Day 15: Polymorphism
Share
Unit 3, Classes & Objects • Cycle 2
Day 15 Advanced Practice • Harder Difficulty
Focus: Polymorphism
Hard
Polymorphism
Advanced Practice Question
Format: Polymorphism
Which method call is valid?
Which method call is valid?
public class Animal {
public void eat() { }
}
public class Dog extends Animal {
public void bark() { }
}
// In another class:
Animal a = new Dog();
Difficulty: Hard |
Topic: Polymorphism |
Cycle: 2 (Advanced)
Why This Answer?
a.eat() works because eat() is in Animal. a.bark() doesn't compile because bark() is not in Animal. ((Dog) a).bark() works because we cast a to Dog type.
Common Mistake
Watch Out!
Thinking a polymorphic reference can call subclass-only methods.
AP Exam Strategy
A Parent reference can only call Parent methods unless you cast down.
Master This Topic
This Cycle 2 HARD question tests polymorphism. Review Unit 3 concepts to build mastery of classes & objects.
- Understanding polymorphism
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs