-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhybrid_inheritence.py
More file actions
81 lines (61 loc) · 1.77 KB
/
hybrid_inheritence.py
File metadata and controls
81 lines (61 loc) · 1.77 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
73
74
75
76
77
78
79
80
81
# ------------------------------------------------
# Example Program: Hybrid Inheritance in Python
# ------------------------------------------------
"""
Inheritance Diagram
ramana
/ \
/ \
DerivedClass1 DerivedClass2
\ /
\ /
FinalDerivedClass
Explanation:
- 'ramana' is the base (parent) class.
- 'DerivedClass1' and 'DerivedClass2' inherit from 'ramana'.
→ This is Hierarchical Inheritance.
- 'FinalDerivedClass' inherits from both 'DerivedClass1' and 'DerivedClass2'.
→ This is Multiple Inheritance.
- Combining both forms Hybrid Inheritance.
"""
# -----------------------------
# Base Class (Parent)
# -----------------------------
class ramana:
# Method in parent class
def reddy(self):
print("Father")
# -----------------------------
# First Child Class
# -----------------------------
class DerivedClass1(ramana):
# Method specific to this class
def poo(self):
print("daughter")
# -----------------------------
# Second Child Class
# -----------------------------
class DerivedClass2(ramana):
# Method specific to this class
def konda(self):
print("Son")
# -----------------------------
# Final Child Class
# -----------------------------
# This class inherits from both DerivedClass1 and DerivedClass2
class FinalDerivedClass(DerivedClass1, DerivedClass2):
# Method specific to this class
def siddamma(self):
print("Mother")
# -----------------------------
# Object Creation
# -----------------------------
obj = FinalDerivedClass()
# Calling method from parent class
obj.reddy()
# Calling method from DerivedClass1
obj.poo()
# Calling method from DerivedClass2
obj.konda()
# Calling method from FinalDerivedClass
obj.siddamma()