Bird
Raised Fist0

Given this Python code snippet, what will be the output?

medium📝 Analysis Q4 of Q15
LLD - Design — Library Management System
Given this Python code snippet, what will be the output?
class Book:
    def __init__(self, title):
        self.title = title

class Member:
    def __init__(self, name):
        self.name = name

loan = Loan(Book('1984'), Member('Alice'))
print(loan.book.title, loan.member.name)

Assuming Loan class stores book and member as attributes.
A1984 Alice
BError: Loan class not defined
CBook object Member object
D1984 None
Step-by-Step Solution
Solution:
  1. Step 1: Check if Loan class is defined

    The code snippet uses Loan but does not define it anywhere, so this will cause a NameError.
  2. Step 2: Understand Python error behavior

    Since Loan is undefined, Python will raise an error before printing anything.
  3. Final Answer:

    Error: Loan class not defined -> Option B
  4. Quick Check:

    Undefined class usage = Error [OK]
Quick Trick: Undefined classes cause runtime errors [OK]
Common Mistakes:
MISTAKES
  • Assuming Loan class exists
  • Expecting attribute access without definition
  • Ignoring NameError on undefined classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes