Bird
Raised Fist0

Consider a chess system where each piece class overrides the move() method. What is the expected behavior when invoking move() on a collection containing different piece objects?

medium📝 Analysis Q4 of Q15
LLD - Design — Chess Game
Consider a chess system where each piece class overrides the move() method. What is the expected behavior when invoking move() on a collection containing different piece objects?
AOnly the first piece in the collection executes its overridden method
BAll pieces execute the base class <code>move()</code> method ignoring overrides
CEach piece executes its own overridden <code>move()</code> method according to its type
DThe system throws an error due to method ambiguity
Step-by-Step Solution
Solution:
  1. Step 1: Recognize polymorphic calls

    Calling move() on a base class reference invokes the overridden method of the actual object type.
  2. Step 2: Apply to mixed collection

    Each piece in the collection calls its own move() implementation dynamically.
  3. Final Answer:

    Each piece executes its own overridden move() method according to its type -> Option C
  4. Quick Check:

    Dynamic dispatch ensures correct method calls [OK]
Quick Trick: Calling move() on mixed pieces triggers each piece's own method [OK]
Common Mistakes:
MISTAKES
  • Assuming base class method is always called
  • Believing only one piece's method runs
  • Expecting runtime errors due to polymorphism

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes