Bird
0
0

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

medium📝 Debug Q14 of 15
Python - Inheritance and Code Reuse

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

class Vehicle:
    def start(self):
        print("Vehicle started")

class Car(Vehicle):
    def start():
        print("Car started")

c = Car()
c.start()
AMissing 'self' parameter in Car's start method
BCar class should not inherit Vehicle
CParent method start() is private and cannot be overridden
DCalling start() without parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature in child class

    Car's start method is missing the 'self' parameter, which is required for instance methods.
  2. Step 2: Understand impact of missing 'self'

    Without 'self', Python treats start as a static method, causing a TypeError when called on an instance.
  3. Final Answer:

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

    Instance methods need 'self' parameter [OK]
Quick Trick: Always include 'self' as first parameter in instance methods [OK]
Common Mistakes:
  • Forgetting 'self' in child method
  • Thinking inheritance causes error
  • Misunderstanding method call syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes