Bird
Raised Fist0

When a subclass object is referenced by a superclass variable and a method is called, which polymorphism pattern determines which method implementation executes?

easy🔍 Pattern Recognition Q2 of Q15
OOP & Design Patterns - Polymorphism - Compile-Time (Overloading) vs Runtime (Overriding)
When a subclass object is referenced by a superclass variable and a method is called, which polymorphism pattern determines which method implementation executes?
ARuntime binding via method overriding and dynamic dispatch.
BCompile-time binding via method overloading resolution.
CStatic binding based on the declared type of the variable.
DEarly binding using the superclass method implementation always.
Step-by-Step Solution
Solution:
  1. Step 1: Understand polymorphism with superclass references

    When a superclass reference points to a subclass object, overridden methods are resolved at runtime using dynamic dispatch.
  2. Step 2: Evaluate options

    A is incorrect because overloading is compile-time and depends on reference type, not object type. B correctly identifies runtime binding via overriding. C is wrong because static binding ignores subclass overrides. D is false; superclass method is not always called.
  3. Final Answer:

    Runtime binding via method overriding and dynamic dispatch -> Option A
  4. Quick Check:

    Overriding uses runtime binding, not compile-time [OK]
Quick Trick: Overriding resolved at runtime, overloading at compile-time [OK]
Common Mistakes:
MISTAKES
  • Assuming method called depends on reference type only
  • Confusing overloading with overriding resolution
  • Believing superclass method always executes
Trap Explanation:
PITFALL
  • Many candidates think the declared type controls method call, ignoring dynamic dispatch.
Interviewer Note:
CONTEXT
  • Checks understanding of dynamic dispatch and runtime polymorphism.
Master "Polymorphism - Compile-Time (Overloading) vs Runtime (Overriding)" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes