Multilevel Inheritance
Illustrate inheritance across multiple levels of a class hierarchy.
BeginnerTopic: Object-Oriented Programs
Python Multilevel Inheritance Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# 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
Understanding Multilevel Inheritance
SportsCar inherits from Car, which inherits from Vehicle, forming a multilevel hierarchy.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.