File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ # ------------------------------------------------
2+ # Example Program: Hierarchical Inheritance
3+ # ------------------------------------------------
4+
5+ """
6+ Inheritance Diagram
7+
8+ konda
9+ / \
10+ / \
11+ DerivedClass DerivedClass1
12+
13+ Explanation:
14+ - 'konda' is the parent class.
15+ - 'DerivedClass' and 'DerivedClass1' are child classes.
16+ - Both child classes inherit from the same parent.
17+ """
18+
19+ # Parent Class
20+ class konda :
21+
22+ # Method inside parent class
23+ def reddy (self ):
24+ print ("kondareddy" )
25+
26+
27+ # First Child Class
28+ class DerivedClass (konda ):
29+
30+ # Method specific to this child class
31+ def kondare (self ):
32+ print ("Kondareddy_Ambavaram" )
33+
34+
35+ # Second Child Class
36+ class DerivedClass1 (konda ):
37+
38+ # Method specific to this child class
39+ def Tiruma (self ):
40+ print ("Ambavaram Tirumala Kondareddy" )
41+
42+
43+ # Creating object of first child class
44+ object1 = DerivedClass ()
45+
46+ # Calling parent method
47+ object1 .reddy ()
48+
49+ # Calling method of DerivedClass
50+ object1 .kondare ()
51+
52+
53+ # Creating object of second child class
54+ object2 = DerivedClass1 ()
55+
56+ # Calling parent method
57+ object2 .reddy ()
58+
59+ # Calling method of DerivedClass1
60+ object2 .Tiruma ()
You can’t perform that action at this time.
0 commit comments