1+ # ------------------------------------------------
2+ # Example Program: Hybrid Inheritance in Python
3+ # ------------------------------------------------
4+
5+ """
6+ Inheritance Diagram
7+
8+ ramana
9+ / \
10+ / \
11+ DerivedClass1 DerivedClass2
12+ \ /
13+ \ /
14+ FinalDerivedClass
15+
16+ Explanation:
17+ - 'ramana' is the base (parent) class.
18+ - 'DerivedClass1' and 'DerivedClass2' inherit from 'ramana'.
19+ → This is Hierarchical Inheritance.
20+ - 'FinalDerivedClass' inherits from both 'DerivedClass1' and 'DerivedClass2'.
21+ → This is Multiple Inheritance.
22+ - Combining both forms Hybrid Inheritance.
23+ """
24+
25+ # -----------------------------
26+ # Base Class (Parent)
27+ # -----------------------------
28+ class ramana :
29+
30+ # Method in parent class
31+ def reddy (self ):
32+ print ("Father" )
33+
34+
35+ # -----------------------------
36+ # First Child Class
37+ # -----------------------------
38+ class DerivedClass1 (ramana ):
39+
40+ # Method specific to this class
41+ def poo (self ):
42+ print ("daughter" )
43+
44+
45+ # -----------------------------
46+ # Second Child Class
47+ # -----------------------------
48+ class DerivedClass2 (ramana ):
49+
50+ # Method specific to this class
51+ def konda (self ):
52+ print ("Son" )
53+
54+
55+ # -----------------------------
56+ # Final Child Class
57+ # -----------------------------
58+ # This class inherits from both DerivedClass1 and DerivedClass2
59+ class FinalDerivedClass (DerivedClass1 , DerivedClass2 ):
60+
61+ # Method specific to this class
62+ def siddamma (self ):
63+ print ("Mother" )
64+
65+
66+ # -----------------------------
67+ # Object Creation
68+ # -----------------------------
69+ obj = FinalDerivedClass ()
70+
71+ # Calling method from parent class
72+ obj .reddy ()
73+
74+ # Calling method from DerivedClass1
75+ obj .poo ()
76+
77+ # Calling method from DerivedClass2
78+ obj .konda ()
79+
80+ # Calling method from FinalDerivedClass
81+ obj .siddamma ()
0 commit comments