Bird
0
0

Identify the error in this Booking class code snippet:

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

booking = Booking(None)
booking.confirm()
ANo error, code runs fine
BSyntaxError in method definition
CAttributeError because room is None
DTypeError in constructor
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor argument

    Booking is created with room set to None.
  2. Step 2: Confirm method tries to set attribute

    confirm() sets self.room.is_available = False, but self.room is None.
  3. Step 3: Resulting error

    Accessing attribute on None causes AttributeError at runtime.
  4. Final Answer:

    AttributeError because room is None -> Option C
  5. Quick Check:

    None object has no attributes = AttributeError [OK]
Quick Trick: Calling attribute on None causes AttributeError [OK]
Common Mistakes:
  • Assuming code runs without error
  • Confusing AttributeError with SyntaxError
  • Expecting TypeError in constructor

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes