Bird
0
0

Identify the issue in this code snippet:

medium📝 Analysis Q6 of 15
LLD - Design — Chess Game
Identify the issue in this code snippet:
class Piece:
    def move(self):
        raise NotImplementedError("Subclasses must implement move")

class Pawn(Piece):
    def move():
        print("Pawn moves forward")

p = Pawn()
p.move()
ANotImplementedError should not be raised in base class
Bmove method in Pawn lacks 'self' parameter
CPawn class should not override move method
DPawn instance creation is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature

    Base class move(self) requires 'self' parameter.
  2. Step 2: Inspect Pawn.move()

    Pawn.move() is missing 'self' parameter, causing a TypeError on call.
  3. Step 3: Confirm error

    Calling p.move() will fail due to incorrect method signature.
  4. Final Answer:

    move method in Pawn lacks 'self' parameter -> Option B
  5. Quick Check:

    Instance methods must include 'self' [OK]
Quick Trick: Instance methods require 'self' parameter [OK]
Common Mistakes:
  • Ignoring missing 'self' in method
  • Thinking NotImplementedError is the problem
  • Assuming method override is optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes