Bird
0
0

Find the error in this code that tries to override a method:

medium📝 Debug Q14 of 15
Python - Polymorphism and Dynamic Behavior
Find the error in this code that tries to override a method:
class Parent:
    def show(self):
        print('Parent show')

class Child(Parent):
    def show():
        print('Child show')

obj = Child()
obj.show()
AMissing self parameter in Child's show method
BParent class method show is private
CChild class should not override show method
Dobj.show() should be called as Child.show(obj)
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature in Child class

    The Child's show method is missing the 'self' parameter, so it is not a proper instance method.
  2. Step 2: Understand impact of missing self

    Calling obj.show() will cause a TypeError because Python expects the first argument (self) but none is defined.
  3. Final Answer:

    Missing self parameter in Child's show method -> Option A
  4. Quick Check:

    Instance methods must have self parameter [OK]
Quick Trick: Instance methods always need self as first parameter [OK]
Common Mistakes:
  • Ignoring missing self parameter
  • Thinking method overriding is not allowed
  • Believing calling method differently fixes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes