Bird
0
0

Consider this code:

medium📝 Analysis Q5 of 15
LLD - Design — Hotel Booking System
Consider this code:
class Room:
    def __init__(self, name):
        self.name = name

class Lab(Room):
    def __init__(self, name, equipment):
        self.equipment = equipment

lab = Lab('Chemistry Lab', ['Microscope'])
print(lab.name, lab.equipment)

What happens when this code runs?
APrints: None ['Microscope']
BPrints: Chemistry Lab ['Microscope']
CError because Room's __init__ is not called
DError because equipment is not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor calls

    Lab's __init__ does not call Room's __init__, so name is not set.
  2. Step 2: Understand attribute access

    Accessing lab.name fails because it was never initialized, causing error.
  3. Final Answer:

    Error because Room's __init__ is not called -> Option C
  4. Quick Check:

    Missing super() call causes attribute error [OK]
Quick Trick: Always call base __init__ to set base attributes [OK]
Common Mistakes:
  • Assuming base attributes auto-set without super()
  • Ignoring missing attribute errors
  • Confusing attribute types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes