Bird
0
0

Which of the following is the correct way to declare a subclass King that extends a base Piece class in a typical object-oriented design?

easy📝 Conceptual Q12 of 15
LLD - Design — Chess Game
Which of the following is the correct way to declare a subclass King that extends a base Piece class in a typical object-oriented design?
Aclass King extends Piece { constructor(position) { super(position); } }
Bfunction King() { this.position = position; } extends Piece
Cclass King inherits Piece { constructor() { } }
DKing = Piece + position
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct subclass syntax

    In modern OOP, a subclass uses extends keyword and calls super() in constructor.
  2. Step 2: Check each option

    class King extends Piece { constructor(position) { super(position); } } uses correct syntax: class King extends Piece { constructor(position) { super(position); } }.
  3. Final Answer:

    class King extends Piece { constructor(position) { super(position); } } -> Option A
  4. Quick Check:

    Subclass syntax = extends + super() [OK]
Quick Trick: Subclass uses extends and calls super() in constructor [OK]
Common Mistakes:
  • Using incorrect keywords like inherits
  • Placing extends after function declaration
  • Trying to add properties with '+' operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes