Bird
0
0

Which of the following is the correct way to define a Player class constructor that stores a player's name and ID in a typical object-oriented design?

easy🧠 Conceptual Q12 of 15
LLD - Design — Tic-Tac-Toe Game
Which of the following is the correct way to define a Player class constructor that stores a player's name and ID in a typical object-oriented design?
Aclass Player { constructor(name, id) { this.name = name; this.id = id; } }
Bclass Player { Player(name, id) { this.name = name; this.id = id; } }
Cfunction Player(name, id) { this.name = name; this.id = id; }
Dclass Player { def __init__(self, name, id): self.name = name; self.id = id }
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct constructor syntax in JavaScript

    In JavaScript ES6+, the constructor method inside a class is named constructor.
  2. Step 2: Check other options for errors

    class Player { Player(name, id) { this.name = name; this.id = id; } } uses a method named Player instead of constructor; function Player(name, id) { this.name = name; this.id = id; } is a function, not a class; class Player { def __init__(self, name, id): self.name = name; self.id = id } uses Python syntax.
  3. Final Answer:

    class Player { constructor(name, id) { this.name = name; this.id = id; } } -> Option A
  4. Quick Check:

    JavaScript class constructor = constructor() [OK]
Quick Trick: JS class constructors use 'constructor' keyword [OK]
Common Mistakes:
MISTAKES
  • Using method named same as class instead of constructor
  • Mixing Python syntax in JavaScript
  • Defining constructor as a separate function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes