Bird
0
0

Given the following code snippet, what will be the output?

medium📝 Analysis Q13 of 15
LLD - Design — Hotel Booking System
Given the following code snippet, what will be the output?
class Room:
    def __init__(self, number):
        self.number = number
        self.is_available = True

class Booking:
    def __init__(self, room):
        self.room = room
        self.room.is_available = False

room101 = Room(101)
print(room101.is_available)
booking1 = Booking(room101)
print(room101.is_available)
ATrue\nTrue
BFalse\nTrue
CFalse\nFalse
DTrue\nFalse
Step-by-Step Solution
Solution:
  1. Step 1: Check initial availability of room101

    When room101 is created, is_available is set to True, so first print outputs True.
  2. Step 2: Booking changes room availability

    Booking constructor sets room101.is_available to False, so second print outputs False.
  3. Final Answer:

    True\nFalse -> Option D
  4. Quick Check:

    Initial True, then set False by Booking [OK]
Quick Trick: Booking sets room availability to False immediately [OK]
Common Mistakes:
  • Assuming availability stays True after booking
  • Confusing order of prints
  • Ignoring side effect on room object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes