-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhierarchical_inheritence.py
More file actions
60 lines (41 loc) · 1.13 KB
/
hierarchical_inheritence.py
File metadata and controls
60 lines (41 loc) · 1.13 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
# ------------------------------------------------
# Example Program: Hierarchical Inheritance
# ------------------------------------------------
"""
Inheritance Diagram
konda
/ \
/ \
DerivedClass DerivedClass1
Explanation:
- 'konda' is the parent class.
- 'DerivedClass' and 'DerivedClass1' are child classes.
- Both child classes inherit from the same parent.
"""
# Parent Class
class konda:
# Method inside parent class
def reddy(self):
print("kondareddy")
# First Child Class
class DerivedClass(konda):
# Method specific to this child class
def kondare(self):
print("Kondareddy_Ambavaram")
# Second Child Class
class DerivedClass1(konda):
# Method specific to this child class
def Tiruma(self):
print("Ambavaram Tirumala Kondareddy")
# Creating object of first child class
object1 = DerivedClass()
# Calling parent method
object1.reddy()
# Calling method of DerivedClass
object1.kondare()
# Creating object of second child class
object2 = DerivedClass1()
# Calling parent method
object2.reddy()
# Calling method of DerivedClass1
object2.Tiruma()