File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # ------------------------------------------------
2+ # Example Program: Multiple Inheritance in Python
3+ # ------------------------------------------------
4+
5+ """
6+ Inheritance Diagram
7+
8+ konda kondare
9+ │ │
10+ │ │
11+ └───────┬─────────┘
12+ │
13+ DerivedClass
14+ │
15+ Tiru()
16+
17+ Explanation:
18+ - 'konda' and 'kondare' are parent classes.
19+ - 'DerivedClass' inherits from both parent classes.
20+ - Therefore, DerivedClass can access methods from both parents.
21+ """
22+
23+ # Parent Class 1
24+ class konda :
25+
26+ # Method inside the first parent class
27+ def reddy (self ):
28+ print ("Kondareddy" )
29+
30+
31+ # Parent Class 2
32+ class kondare :
33+
34+ # Method inside the second parent class
35+ def Ambavaram (self ):
36+ print ("Tirumala" )
37+
38+
39+ # Child Class inheriting from both parent classes
40+ # This demonstrates Multiple Inheritance
41+ class DerivedClass (konda , kondare ):
42+
43+ # Method defined in the child class
44+ def Tiru (self ):
45+ print ("Ambavaram Tirumala Kondareddy" )
46+
47+
48+ # Creating an object of the child class
49+ obj = DerivedClass ()
50+
51+ # Calling method from Parent Class 1
52+ obj .reddy ()
53+
54+ # Calling method from Parent Class 2
55+ obj .Ambavaram ()
56+
57+ # Calling method from Child Class
58+ obj .Tiru ()
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments