-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice_multiple_inheritence.py
More file actions
58 lines (42 loc) · 1.29 KB
/
practice_multiple_inheritence.py
File metadata and controls
58 lines (42 loc) · 1.29 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
# ------------------------------------------------
# Example Program: Multiple Inheritance in Python
# ------------------------------------------------
"""
Inheritance Diagram
konda kondare
│ │
│ │
└───────┬─────────┘
│
DerivedClass
│
Tiru()
Explanation:
- 'konda' and 'kondare' are parent classes.
- 'DerivedClass' inherits from both parent classes.
- Therefore, DerivedClass can access methods from both parents.
"""
# Parent Class 1
class konda:
# Method inside the first parent class
def reddy(self):
print("Kondareddy")
# Parent Class 2
class kondare:
# Method inside the second parent class
def Ambavaram(self):
print("Tirumala")
# Child Class inheriting from both parent classes
# This demonstrates Multiple Inheritance
class DerivedClass(konda, kondare):
# Method defined in the child class
def Tiru(self):
print("Ambavaram Tirumala Kondareddy")
# Creating an object of the child class
obj = DerivedClass()
# Calling method from Parent Class 1
obj.reddy()
# Calling method from Parent Class 2
obj.Ambavaram()
# Calling method from Child Class
obj.Tiru()