Bird
Raised Fist0

Given this Python-like pseudocode for room types:

medium📝 Analysis Q13 of Q15
LLD - Design — Hotel Booking System
Given this Python-like pseudocode for room types:
class Room:
    def __init__(self, name):
        self.name = name

class Bedroom(Room):
    def __init__(self, name, bed_size):
        super().__init__(name)
        self.bed_size = bed_size

room = Bedroom('Master', 'King')
print(room.name, room.bed_size)

What will be the output?
AError: missing argument
BBedroom King
CMaster None
DMaster King
Step-by-Step Solution
Solution:
  1. Step 1: Trace object creation

    Creating Bedroom('Master', 'King') calls Bedroom's constructor, which calls Room's constructor with 'Master'.
  2. Step 2: Check printed attributes

    room.name is 'Master' from Room; room.bed_size is 'King' from Bedroom.
  3. Final Answer:

    Master King -> Option D
  4. Quick Check:

    Subclass calls base, attributes set correctly [OK]
Quick Trick: Remember: super() sets base class attributes [OK]
Common Mistakes:
MISTAKES
  • Assuming subclass overwrites base attributes
  • Forgetting to call super().__init__
  • Confusing attribute names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes