22. Problem to show multilevel inheritance example in multiple classes

In this Python oops program, we will show multilevel inheritance example in multiple classes. This example demonstrates the concept of class inheritance and method overriding in Python. 

Multilevel Inheritance Example

Steps to solve the program
  1. Five classes (Class1, Class2, Class3, Class4, and Class5) are defined. Each class is derived from its respective parent class, forming an inheritance hierarchy.
  2. Each class has a single method that prints a specific message.
  3. An object (obj) of the final class, Class5, is created.
  4. By creating an instance of Class5, we have access to all the methods defined in Class5, as well as the methods inherited from its parent classes (Class4, Class3, Class2, and Class1).
  5. The methods are called using dot notation on the obj object.

Output:

Related Articles

Create 5 different Python Classes and access them via a single class object.

Set Instance variable data with setattr and getattr methods.

Leave a Comment