-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_multi_level_inheritance.py
More file actions
39 lines (29 loc) · 1006 Bytes
/
python_multi_level_inheritance.py
File metadata and controls
39 lines (29 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Example of Multilevel Inheritance in Python
# Base (Grandparent) Class
class konda:
# Method defined in the base class
def kondaa(self):
# Prints a message
print("kondareddy")
# Derived Class (Parent) inheriting from konda
class DerivedClass(konda):
# Method defined in the parent class
def ambavaram(self):
# Prints a message
print("ambavaram_konda")
# Second Derived Class (Child) inheriting from DerivedClass
# This creates a multilevel inheritance chain: konda → DerivedClass → DerivedClass1
class DerivedClass1(DerivedClass):
# Method defined in the child class
def Tirumala(self):
# Prints a message
print("Tirumala_konda")
# Creating an object of the final child class
# The object can access methods from all levels of inheritance
obj = DerivedClass1()
# Calling method from the base class
obj.kondaa()
# Calling method from the parent class
obj.ambavaram()
# Calling method from the child class
obj.Tirumala()