Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Python - Inheritance and Code Reuse

What will be the output of this code?

class A:
    def show(self):
        print('A show')

class B(A):
    def show(self):
        super().show()
        print('B show')

obj = B()
obj.show()
AA show
BError: super() used incorrectly
CB show
DA show\nB show
Step-by-Step Solution
Solution:
  1. Step 1: Understand super() call in B's show

    super().show() calls A's show method, printing 'A show'.
  2. Step 2: Follow with B's own print

    After calling parent method, B prints 'B show'.
  3. Final Answer:

    A show\nB show -> Option D
  4. Quick Check:

    super() calls parent method before child code [OK]
Quick Trick: super() calls parent method inside child method [OK]
Common Mistakes:
  • Expecting only B show
  • Expecting only A show
  • Thinking super() causes error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes