Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q4 of Q15
Python - Classes and Object Lifecycle
What will be the output of this code?
class MyClass:
    def __init__(self):
        print('Object created')

obj = MyClass()
AObject deleted
BNo output
CError: __init__ not defined
DObject created
Step-by-Step Solution
Solution:
  1. Step 1: Understand __init__ method role

    The __init__ method runs automatically when an object is created and prints 'Object created'.
  2. Step 2: Trace code execution

    Creating obj calls __init__, so 'Object created' is printed.
  3. Final Answer:

    Object created -> Option D
  4. Quick Check:

    __init__ runs on creation = Prints message [OK]
Quick Trick: __init__ runs on object creation to initialize [OK]
Common Mistakes:
MISTAKES
  • Expecting no output
  • Confusing __init__ with destructor
  • Thinking __init__ must be called manually

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes