Class inheritance

class Vehicle:
    def __init__(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year

    def start_engine(self):
        print("Engine started!")

    def stop_engine(self):
        print("Engine stopped!")


class Car(Vehicle):
    def drive(self):
        print("Car is being driven!")
my_car = Car("Toyota", "Camry", 2022)
print(my_car.make)  # Output: Toyota
print(my_car.model)  # Output: Camry
print(my_car.year)  # Output: 2022

my_car.start_engine()  # Output: Engine started!
my_car.drive()  # Output: Car is being driven!
my_car.stop_engine()  # Output: Engine stopped!
Toyota
Camry
2022
Engine started!
Car is being driven!
Engine stopped!
class Car(Vehicle):
    def drive(self):
        print("Car is being driven!")

    def stop_engine(self):
        print("Car engine stopped!")  # Override the stop_engine method
CTRL + ENTER to send