Python Practice › OOP Programs › Program 11
Multilevel inheritance
Write a Python program that demonstrates multilevel inheritance.
Output
4 petrol 300
Approach
- A grandchild inherits from a child, which inherits from a parent.
Solution
class Vehicle: def wheels(self): return 4 class Car(Vehicle): def fuel(self): return "petrol" class SportsCar(Car): def speed(self): return 300 s = SportsCar()print(s.wheels(), s.fuel(), s.speed())Output
4 petrol 300
Learn the concept
New to this topic? Read the lesson, then come back.