Bird
0
0

How should you write the start method in Car?

hard📝 Application Q8 of 15
Python - Inheritance and Code Reuse

You have a class Vehicle with a method start that prints "Vehicle started". You want to create a Car class that overrides start to print "Car started" but also call the Vehicle start method. How should you write the start method in Car?

Adef start(self):<br> print('Car started')<br> Vehicle.start()
Bdef start(self):<br> super().start()<br> print('Car started')
Cdef start(self):<br> print('Car started')
Ddef start(self):<br> Vehicle.start()
Step-by-Step Solution
Solution:
  1. Step 1: Use super() to call parent method

    super().start() calls Vehicle's start method properly with self.
  2. Step 2: Add Car's own print after parent call

    Printing 'Car started' after calling parent method shows both messages.
  3. Final Answer:

    def start(self): super().start() print('Car started') -> Option B
  4. Quick Check:

    Use super() to call parent method inside override [OK]
Quick Trick: Call parent method with super() before child code [OK]
Common Mistakes:
  • Calling Vehicle.start without self
  • Not calling parent method at all
  • Calling parent method after child's print (if order matters)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes