-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice_multilevel_inheritence.py
More file actions
72 lines (55 loc) · 1.55 KB
/
Copy pathpractice_multilevel_inheritence.py
File metadata and controls
72 lines (55 loc) · 1.55 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# ------------------------------------------------
# Example Program: Multilevel Inheritance in Python
# ------------------------------------------------
"""
Inheritance Diagram
konda
│
│
DerivedClass
│
│
DerivedClass2
Explanation:
- 'konda' is the base (parent) class.
- 'DerivedClass' inherits from 'konda'.
- 'DerivedClass2' inherits from 'DerivedClass'.
- This creates a chain of inheritance called Multilevel Inheritance.
"""
# -----------------------------
# Base Class (Level 1)
# -----------------------------
class konda:
# Method inside base class
def reddy(self):
print("konda")
# -----------------------------
# Derived Class (Level 2)
# -----------------------------
# This class inherits from 'konda'
class DerivedClass(konda):
# Method defined in this class
def Kondare(self):
print("Ambavaram")
# -----------------------------
# Second Derived Class (Level 3)
# -----------------------------
# This class inherits from 'DerivedClass'
class DerivedClass2(DerivedClass):
# Method defined in this class
def Tirum(self):
print("Tirumala")
# -----------------------------
# Object Creation
# -----------------------------
# Creating object of the last child class
object = DerivedClass2()
# -----------------------------
# Calling Methods
# -----------------------------
# Method from base class (konda)
object.reddy()
# Method from intermediate class (DerivedClass)
object.Kondare()
# Method from final child class (DerivedClass2)
object.Tirum()