Bird
0
0

Why does a child class need to call super().__init__() when it defines its own __init__ method?

hard📝 Conceptual Q10 of 15
Python - Inheritance and Code Reuse
Why does a child class need to call super().__init__() when it defines its own __init__ method?
ATo ensure the parent class is properly initialized
BTo override the parent class completely
CTo prevent the child class from having attributes
DIt is optional and has no effect
Step-by-Step Solution
Solution:
  1. Step 1: Understand constructor chaining

    If a child defines __init__, it replaces parent's __init__, so parent's initialization won't run unless called explicitly.
  2. Step 2: Purpose of super().__init__()

    Calling super().__init__() runs parent's __init__, setting up inherited attributes correctly.
  3. Final Answer:

    To ensure the parent class is properly initialized -> Option A
  4. Quick Check:

    super().__init__() runs parent's constructor [OK]
Quick Trick: Call super().__init__() to initialize parent attributes [OK]
Common Mistakes:
  • Thinking it's optional without consequences
  • Believing it overrides parent completely
  • Assuming child can't have attributes if called

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes