LAB MANUAL
Python Program
Demonstrating
Multilevel
Inheritance
Disclaimer: The content is curated from online/offline resources and used for educational purpose only
Disclaimer: The content is curated from online/offline resources and used for educational purpose only
Python Program Demonstrating Multilevel Inheritance
Objectives:
To understand and implement multilevel inheritance in Python using classes.
To create a base class Person to store common personal details, a derived class
Employee to store employee-related details, and a further derived class Manager that
extends Employee to store manager-specific details.
To demonstrate how attributes and methods are passed through multiple levels of
inheritance.
Problem Statement:
Create a base class Person to store common personal details such as name and age. Then, an
employee class will be derived from Person to include employee-related details such as
employee ID and salary. Finally, the Manager class will inherit from Employee and add specific
details like department and team size. The program will demonstrate how attributes and
methods are passed down through multiple levels of inheritance.
Procedure:
Task 1: Define the Base Class Person
Task 2: Define the Derived Class Employee
Task 3: Define the Further Derived Class Manager
Task 4: Instantiate Objects from the Manager Class
Code:
Task 1: Define the Base Class Person
The Person class is the base class, which contains common personal details like name and
age. The display_personal_details() method returns a string containing the person's name and
age.
Disclaimer: The content is curated from online/offline resources and used for educational purpose only
Task 2: Define the Derived Class Employee
The Employee class inherits from Person and adds employee-specific attributes like
employee_id and salary.
The __init__ method uses super() to call the constructor of the Person class to initialize the
inherited attributes (name and age).
Task 3: Define the Further Derived Class Manager
The Manager class inherits from Employee, adding specific attributes for managers like
department and team_size. The __init__ method calls the constructor of the Employee class to
initialize inherited attributes (name, age, employee_id, salary). The display_manager_details()
method displays the manager's details along with personal and employee information by calling
display_employee_details() from the Employee class.
Disclaimer: The content is curated from online/offline resources and used for educational purpose only
Task 4: Instantiate Objects from the Manager Class
An object manager is created from the Manager class with the name "Ramar Bose", age 45,
employee ID "M12345", salary of ₹95,000, department "Sales", and a team size of 10.
The display_manager_details() method is called to print all the details inherited from both
Person and Employee, as well as manager-specific details.
Output:
This program demonstrates multilevel inheritance in Python by extending functionality across
multiple levels of classes: Person, Employee, and Manager. The Manager class inherits
attributes and methods from both its parent class (Employee) and grandparent class (Person).
Disclaimer: The content is curated from online/offline resources and used for educational purpose only