Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Python - Inheritance and Code Reuse
Find the error in this code:
class Parent:
    def hello(self):
        print("Hello from Parent")

class Child(Parent):
    def hello(self):
        super.hello()

c = Child()
c.hello()
Asuper.hello() should be super().hello()
BMissing self argument in hello()
CChild class should not override hello()
DParent class method hello() is private
Step-by-Step Solution
Solution:
  1. Step 1: Identify how super() is called

    The code uses super.hello() which is incorrect syntax.

  2. Step 2: Correct syntax for super()

    It should be super().hello() with parentheses after super.

  3. Final Answer:

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

    super() requires parentheses [OK]
Quick Trick: Always use super() with parentheses [OK]
Common Mistakes:
  • Omitting parentheses after super
  • Passing self explicitly to super method
  • Thinking parent method is private

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes