@@ -60,6 +60,31 @@ def set_variable(self, k, v):
60
60
print ('Key-value argument makes the class model easily scalable in python.' )
61
61
self .variables [k ]= v
62
62
63
+ class Phone :
64
+ def __init__ (self ):
65
+ print ('parent class' )
66
+
67
+ def buttons (self ):
68
+ print ('Has buttons to dial a number.' )
69
+
70
+ def screen (self ):
71
+ print ('Phone has a black and white display!' )
72
+
73
+ class Mobile_phone (Phone ):
74
+ def __init__ (self ):
75
+ print ('Child class of Phone' )
76
+
77
+ def internet_connection (self ):
78
+ print ('Can connect to internet using WiFi!' )
79
+
80
+ def buttons (self ):
81
+ print ('Buttons on touch screen! -> Overriding buttons from Parent class Phones!' )
82
+
83
+ def screen (self ):
84
+ super ().screen ()# method to access parent class methods
85
+ print ('Display is colored as a whole.' )
86
+
87
+
63
88
def main ():
64
89
# instantiate: make object of the class
65
90
f = Fibonacci (0 ,1 )
@@ -84,4 +109,17 @@ def main():
84
109
marty .set_variable ('intelligence' ,'VeryHighIntell' )
85
110
print ('Getting new value of\' intelligence\' :' ,marty .get_variable ('intelligence' ))
86
111
112
+ print ()
113
+ print ('Explaining Inheritance in Python OOP:' )
114
+ telepone = Phone ()
115
+ print ('Methods of obj telephone:' )
116
+ telepone .buttons ()
117
+ telepone .screen ()
118
+ samsung = Mobile_phone ()
119
+ print ('Methods of derived class:' )
120
+ samsung .internet_connection ()
121
+ samsung .buttons ()
122
+ samsung .screen ()
123
+
124
+
87
125
if __name__ == '__main__' :main ()