219 Inheritance
Learn how inheritance allows classes to share code and create powerful hierarchies in OOP.
Objectives
What is inheritance?
Example:
class Vehicle:
def __init__(self, brand):
self.brand = brand
def start_engine(self):
return "Engine started"
class Car(Vehicle): # Car inherits from Vehicle
def play_radio(self):
return "Playing music"Using the subclass
Output
Why use inheritance?
Last updated
Was this helpful?