Multilevel Inheritance in Python
Illustrate inheritance across multiple levels of a class hierarchy.
BeginnerObject-Oriented ProgramsExample 6 of 25
multilevel-inheritance.py
Run in browser1# Program to demonstrate multilevel inheritance23class Vehicle:4 def move(self):5 print("Vehicle is moving")67class Car(Vehicle):8 def wheels(self):9 print("Car has 4 wheels")1011class SportsCar(Car):12 def turbo(self):13 print("Sports car has turbo mode")1415sc = SportsCar()16sc.move()17sc.wheels()18sc.turbo()
Output
Vehicle is moving Car has 4 wheels Sports car has turbo mode
What's going on
SportsCar inherits from Car, which inherits from Vehicle, forming a multilevel hierarchy.