Multilevel Inheritance in Python

Illustrate inheritance across multiple levels of a class hierarchy.

BeginnerObject-Oriented ProgramsExample 6 of 25
multilevel-inheritance.py
Run in browser
1# Program to demonstrate multilevel inheritance
2
3class Vehicle:
4 def move(self):
5 print("Vehicle is moving")
6
7class Car(Vehicle):
8 def wheels(self):
9 print("Car has 4 wheels")
10
11class SportsCar(Car):
12 def turbo(self):
13 print("Sports car has turbo mode")
14
15sc = 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.