Bird
Raised Fist0

Find the error in this code that tries to extend the parent method:

medium📝 Debug Q14 of Q15
Python - Inheritance and Code Reuse
Find the error in this code that tries to extend the parent method:
class Parent:
    def show(self):
        print('Parent show')

class Child(Parent):
    def show(self):
        super.show()
        print('Child show')
Asuper.show() should be super().show()
BChild class must not override show()
CParent class method show() is missing self
Dprint statements must be inside __init__
Step-by-Step Solution
Solution:
  1. Step 1: Check super() usage

    The code uses super.show() which is incorrect syntax; super() must be called as a function.
  2. Step 2: Correct the syntax

    It should be super().show() to properly call the parent method.
  3. Final Answer:

    super.show() should be super().show() -> Option A
  4. Quick Check:

    super() needs parentheses to call methods = A [OK]
Quick Trick: Always use super() with parentheses to call parent methods [OK]
Common Mistakes:
MISTAKES
  • Forgetting parentheses after super
  • Thinking parent method needs no self
  • Believing print must be in __init__

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes