Bird
0
0

Identify the error in this code:

medium📝 Analysis Q6 of 15
LLD - Design — Hotel Booking System
Identify the error in this code:
class Room:
    def __init__(self, name):
        self.name = name

class Office(Room):
    def __init__(self, name, floor):
        self.floor = floor

office = Office('Main Office', 3)
print(office.name, office.floor)
AOffice.__init__ does not call Room.__init__, so name is missing
BOffice class should not have __init__ method
CRoom class should not have __init__ method
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor chaining

    Office.__init__ overrides Room.__init__ but does not call it, so name is not set.
  2. Step 2: Result of missing call

    Accessing office.name will cause an error or print undefined.
  3. Final Answer:

    Office.__init__ does not call Room.__init__, so name is missing -> Option A
  4. Quick Check:

    Missing super() call causes missing attributes [OK]
Quick Trick: Call base __init__ in subclass to set base attributes [OK]
Common Mistakes:
  • Ignoring need for super() in subclass __init__
  • Assuming base attributes set automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes