Bird
Raised Fist0

Identify the error in this chess piece design code snippet:

medium📝 Analysis Q14 of Q15
LLD - Design — Chess Game
Identify the error in this chess piece design code snippet:
class Piece { move() { throw 'Not implemented'; } } class Queen extends Piece { } let q = new Queen(); q.move();
AQueen class should not inherit from Piece
BPiece class should not have a move() method
CQueen class does not override move(), causing runtime error
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Analyze base class move() method

    Piece.move() throws an error if called directly, indicating it must be overridden.
  2. Step 2: Check Queen class implementation

    Queen does not override move(), so calling q.move() calls base method and throws error.
  3. Final Answer:

    Queen class does not override move(), causing runtime error -> Option C
  4. Quick Check:

    Abstract method not overridden = runtime error [OK]
Quick Trick: Abstract methods must be overridden to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Assuming base method runs without error
  • Thinking inheritance is wrong here
  • Ignoring the throw statement in base method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes