Bird
0
0

Which of the following is the correct way to initialize the Floor class in Python with a floor number attribute?

easy🧠 Conceptual Q3 of 15
LLD - Design — Elevator System
Which of the following is the correct way to initialize the Floor class in Python with a floor number attribute?
Adef init(self, floor): self.floor = floor
Bdef __init__(self): self.floor = number
Cdef __init__(self, number): self.number = number
Ddef __start__(self, floor): self.floor = floor
Step-by-Step Solution
Solution:
  1. Step 1: Understand Python constructor syntax

    The constructor method must be named __init__ and accept self as the first parameter.
  2. Step 2: Assign the floor number correctly

    The floor number should be passed as a parameter and assigned to an instance variable.
  3. Final Answer:

    def __init__(self, number): self.number = number -> Option C
  4. Quick Check:

    Constructor name and parameter assignment [OK]
Quick Trick: Constructor must be __init__ with self and parameters [OK]
Common Mistakes:
MISTAKES
  • Using wrong constructor name like __start__
  • Missing self parameter
  • Incorrect assignment of parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes