Bird
0
0

Given this code, what will be the output?

hard📝 Predict Output Q9 of 15
Python - Inheritance and Code Reuse
Given this code, what will be the output?
class Parent:
    def process(self):
        print('Parent start')

class Child(Parent):
    def process(self):
        print('Child start')
        super().process()
        print('Child end')

obj = Child()
obj.process()
AChild start Parent start Child end
BParent start Child start Child end
CChild start Child end Parent start
DError due to super()
Step-by-Step Solution
Solution:
  1. Step 1: Trace the method calls in Child.process()

    First prints 'Child start', then calls super().process() which prints 'Parent start', then prints 'Child end'.

  2. Step 2: Determine output order

    Output lines are 'Child start', 'Parent start', 'Child end' in that order.

  3. Final Answer:

    Child start Parent start Child end -> Option A
  4. Quick Check:

    super() runs parent between child's prints = B [OK]
Quick Trick: super() runs parent method exactly where called [OK]
Common Mistakes:
  • Assuming parent prints first
  • Expecting error from super()
  • Mixing print order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes