Multilevel Inheritance

Illustrate inheritance across multiple levels of a class hierarchy.

PythonBeginner
Python
# Program to demonstrate multilevel inheritance

class Vehicle:
    def move(self):
        print("Vehicle is moving")


class Car(Vehicle):
    def wheels(self):
        print("Car has 4 wheels")


class SportsCar(Car):
    def turbo(self):
        print("Sports car has turbo mode")


sc = SportsCar()
sc.move()
sc.wheels()
sc.turbo()

Output

Vehicle is moving
Car has 4 wheels
Sports car has turbo mode

SportsCar inherits from Car, which inherits from Vehicle, forming a multilevel hierarchy.