1
00:00:00,000 --> 00:00:01,000
Hello guys.

2
00:00:01,000 --> 00:00:03,000
So we are going to continue the discussion with respect to Python.

3
00:00:03,000 --> 00:00:06,000
And we are going to continue the object oriented programming series.

4
00:00:06,000 --> 00:00:09,000
And in this video we are going to discuss about polymorphism.

5
00:00:09,000 --> 00:00:15,000
Now polymorphism is a core concept in object oriented programming that allows object of different class

6
00:00:15,000 --> 00:00:18,000
to be treated as objects of a common superclass.

7
00:00:18,000 --> 00:00:21,000
I know there will be a lot of confusion when you read this sentence.

8
00:00:21,000 --> 00:00:24,000
Uh, but just go ahead and read the next line.

9
00:00:24,000 --> 00:00:28,000
And if you are not even understanding over here, don't worry, I will show you a lot of practical example

10
00:00:28,000 --> 00:00:31,000
which will actually help you to understand each and everything.

11
00:00:31,000 --> 00:00:37,000
So it provides you a way to perform a single action in different forms.

12
00:00:37,000 --> 00:00:37,000
Okay.

13
00:00:38,000 --> 00:00:41,000
Poly form ism basically means multiple form okay.

14
00:00:41,000 --> 00:00:45,000
If you split this word it is basically called as multiple form okay.

15
00:00:45,000 --> 00:00:51,000
And here it is written polymorphism is typically achieved through method overriding and interfaces.

16
00:00:51,000 --> 00:00:57,000
So let me just go in and talk about this, and let me just give you a good example to make you understand,

17
00:00:57,000 --> 00:00:57,000
okay.

18
00:00:58,000 --> 00:01:03,000
But it is my duty to probably write this kind of definition so that you also know the definition with

19
00:01:03,000 --> 00:01:03,000
respect to this.

20
00:01:03,000 --> 00:01:04,000
Okay.

21
00:01:04,000 --> 00:01:09,000
Now what does method overriding allows a child class.

22
00:01:09,000 --> 00:01:16,000
So here I'm just going to give you this command C or let me make this or remove this completely.

23
00:01:16,000 --> 00:01:20,000
And and let me make or add a markdown over here.

24
00:01:21,000 --> 00:01:26,000
So here you can see let me just go ahead and execute this method.

25
00:01:26,000 --> 00:01:32,000
Overriding allows the child class to provide a specific implementation of a method that is already defined

26
00:01:32,000 --> 00:01:33,000
in the parent class.

27
00:01:33,000 --> 00:01:34,000
Okay.

28
00:01:34,000 --> 00:01:37,000
That basically means let's say if I'm defining a parent class, okay.

29
00:01:37,000 --> 00:01:39,000
Over there I have defined a method, right?

30
00:01:39,000 --> 00:01:45,000
Uh, let's say the method will be like, uh, if I probably create a dog class, the method is speak.

31
00:01:45,000 --> 00:01:49,000
Okay, so one dog, uh, makes a sound.

32
00:01:49,000 --> 00:01:50,000
Woof woof woof.

33
00:01:50,000 --> 00:01:55,000
Then let's say that I'm inheriting that particular dog with some child class.

34
00:01:55,000 --> 00:01:57,000
Now, that particular dog makes a louder sound.

35
00:01:57,000 --> 00:01:59,000
Woof woof woof woof woof.

36
00:01:59,000 --> 00:02:04,000
So there what we are doing, we are overriding the functionality of that particular method.

37
00:02:04,000 --> 00:02:04,000
Right.

38
00:02:04,000 --> 00:02:09,000
So method overriding is nothing, but it allows a child class to provide a specific implementation of

39
00:02:09,000 --> 00:02:11,000
a method that is already defined in its parent class.

40
00:02:11,000 --> 00:02:14,000
So let me just go ahead and take one specific example.

41
00:02:14,000 --> 00:02:16,000
And here you'll be able to understand.

42
00:02:16,000 --> 00:02:20,000
So first of all I will go ahead and create my base class okay.

43
00:02:20,000 --> 00:02:23,000
Now this base class will be my animal class okay.

44
00:02:23,000 --> 00:02:25,000
So let's say that this is my animal class.

45
00:02:25,000 --> 00:02:29,000
And I'm going to just going to create a function that is called as speak.

46
00:02:29,000 --> 00:02:33,000
And here I have not written any constructor because I'm not defining any attributes.

47
00:02:33,000 --> 00:02:33,000
Okay.

48
00:02:33,000 --> 00:02:39,000
So let's say that I've used speak and with the self parameter and it is just going to return something

49
00:02:39,000 --> 00:02:45,000
like the sound sound of the animal okay.

50
00:02:45,000 --> 00:02:46,000
Something like this.

51
00:02:46,000 --> 00:02:48,000
Now this becomes my base class.

52
00:02:48,000 --> 00:02:50,000
Now let me just go ahead and derive my derive class okay.

53
00:02:51,000 --> 00:02:53,000
Or write down my derive class one.

54
00:02:53,000 --> 00:03:00,000
Now in this derive derived class, let's say I will go ahead and derive or I'll create a child class

55
00:03:00,000 --> 00:03:04,000
which is called as dog and it is basically inheriting from animal.

56
00:03:04,000 --> 00:03:04,000
Okay.

57
00:03:04,000 --> 00:03:09,000
And then we go ahead and define the definition definition speak.

58
00:03:09,000 --> 00:03:11,000
And here we go ahead and define self.

59
00:03:11,000 --> 00:03:13,000
Right now.

60
00:03:13,000 --> 00:03:15,000
See the method is same over here.

61
00:03:15,000 --> 00:03:16,000
Right.

62
00:03:16,000 --> 00:03:20,000
If we are inheriting this particular class, you will be able to see that.

63
00:03:20,000 --> 00:03:20,000
Okay, fine.

64
00:03:20,000 --> 00:03:23,000
This is the method that I have right over here.

65
00:03:23,000 --> 00:03:26,000
And I can also go ahead and return my own definition.

66
00:03:26,000 --> 00:03:30,000
So let's say the dog makes a sound like woof.

67
00:03:30,000 --> 00:03:33,000
Okay, so this is the sound that the dog makes.

68
00:03:33,000 --> 00:03:38,000
So what I have actually done the same method is there but different implementation.

69
00:03:38,000 --> 00:03:42,000
So here method overriding allows a child class to provide a specific implementation of a method that

70
00:03:42,000 --> 00:03:47,000
is already defined in the parent class, so this method is already present over there, but the child

71
00:03:47,000 --> 00:03:53,000
class has provided its own specific definition or implementation right now, let me just go ahead and

72
00:03:53,000 --> 00:03:55,000
create another derived class okay, derived class.

73
00:03:55,000 --> 00:04:01,000
And this time I will go ahead and create a class that is called as Cat and let this get inherited with

74
00:04:01,000 --> 00:04:02,000
animal.

75
00:04:02,000 --> 00:04:03,000
Okay animal.

76
00:04:04,000 --> 00:04:09,000
Now here I can again go ahead and override the functionality of this method.

77
00:04:09,000 --> 00:04:11,000
And here I can say, hey, it returns meow.

78
00:04:12,000 --> 00:04:13,000
Okay.

79
00:04:14,000 --> 00:04:15,000
It returns meow.

80
00:04:15,000 --> 00:04:18,000
Now let's go ahead and define our or create our object.

81
00:04:18,000 --> 00:04:22,000
So here what I'm actually going to do I will just go ahead and write dog is equal to dog.

82
00:04:22,000 --> 00:04:23,000
Okay.

83
00:04:23,000 --> 00:04:30,000
Now if I go ahead and print dog dot speak now which method it is going to just call, it is just going

84
00:04:30,000 --> 00:04:32,000
to make sure that it calls this specific method.

85
00:04:32,000 --> 00:04:33,000
Right.

86
00:04:33,000 --> 00:04:37,000
And similarly, let's say that I go ahead and create my cat okay.

87
00:04:37,000 --> 00:04:47,000
And let's say that here I will just go ahead and print cat dot speak okay.

88
00:04:47,000 --> 00:04:52,000
Now if I go ahead and execute this here, you'll be able to see that hey I am getting when I go ahead

89
00:04:52,000 --> 00:04:58,000
and execute dog dot speak, I'm actually getting woof when I'm uh, executing cat dot speak.

90
00:04:58,000 --> 00:04:59,000
I'm getting meow.

91
00:05:00,000 --> 00:05:02,000
And this is what Mr. Method overriding is all about.

92
00:05:02,000 --> 00:05:07,000
You know, the same method is getting overridden in the derived class with its own implementation.

93
00:05:07,000 --> 00:05:08,000
Right.

94
00:05:08,000 --> 00:05:10,000
And, uh, I can also do one thing.

95
00:05:10,000 --> 00:05:10,000
Okay.

96
00:05:10,000 --> 00:05:15,000
Uh, after doing all these things, you know, I can also create one additional function.

97
00:05:15,000 --> 00:05:18,000
So function that demonstrates.

98
00:05:20,000 --> 00:05:22,000
Demonstrates polymorphism.

99
00:05:24,000 --> 00:05:25,000
Here, what I will do.

100
00:05:25,000 --> 00:05:28,000
I'll go ahead and create a function.

101
00:05:28,000 --> 00:05:30,000
And this is a public function, not inside a class okay.

102
00:05:30,000 --> 00:05:32,000
Not inside any class.

103
00:05:32,000 --> 00:05:34,000
So let's say that I'm going to create animal speak.

104
00:05:34,000 --> 00:05:40,000
And here we will provide an attribute of the class or object of the class okay.

105
00:05:40,000 --> 00:05:46,000
And then we can just go ahead and write print animal dot speak method.

106
00:05:46,000 --> 00:05:46,000
Okay.

107
00:05:46,000 --> 00:05:53,000
Now this animal that I am actually providing, it's an object object of this specific classes.

108
00:05:53,000 --> 00:05:57,000
Now after defining this method I can just go ahead and write print okay.

109
00:05:57,000 --> 00:06:05,000
And I can go ahead and say dog dot speak or let me just go ahead and uh, sorry, it should be animal

110
00:06:06,000 --> 00:06:07,000
underscore speak.

111
00:06:08,000 --> 00:06:10,000
And here I will just be providing dog once.

112
00:06:10,000 --> 00:06:13,000
I probably define this and execute it.

113
00:06:13,000 --> 00:06:19,000
Here you can see that I'm getting hoof right because as soon as I call this function here, we are giving

114
00:06:19,000 --> 00:06:20,000
the object of this particular class.

115
00:06:20,000 --> 00:06:26,000
And inside the same dot speak method is basically getting called right.

116
00:06:26,000 --> 00:06:29,000
So this way also you can probably show polymorphism.

117
00:06:29,000 --> 00:06:32,000
But here what we have done, we have done method overriding.

118
00:06:32,000 --> 00:06:37,000
We have we are just overridden all the functions over here from the base class till the child class.

119
00:06:37,000 --> 00:06:38,000
Okay.

120
00:06:38,000 --> 00:06:40,000
So this was one example over here.

121
00:06:40,000 --> 00:06:48,000
Now let me just show you one more, another way where I will be showing you polymorphism with functions

122
00:06:48,000 --> 00:06:49,000
and methods.

123
00:06:51,000 --> 00:06:52,000
Functions and methods okay.

124
00:06:53,000 --> 00:07:00,000
Now polymorphism can be also implemented using function and methods to process objects of different

125
00:07:00,000 --> 00:07:01,000
types in the same way.

126
00:07:01,000 --> 00:07:02,000
Right?

127
00:07:02,000 --> 00:07:05,000
So here let me just go ahead and show you one base class.

128
00:07:05,000 --> 00:07:09,000
Let me just go ahead and create one base class here.

129
00:07:09,000 --> 00:07:10,000
The class will name will be shape.

130
00:07:10,000 --> 00:07:12,000
Let's say that I'm going to define shape.

131
00:07:12,000 --> 00:07:15,000
Now let me just go ahead and write definition area.

132
00:07:15,000 --> 00:07:18,000
So I'm going to create a function which is called as area.

133
00:07:18,000 --> 00:07:23,000
And here I'm going to give my self keyword okay self Self keyword.

134
00:07:23,000 --> 00:07:32,000
Now let's go ahead and return the area of the area of the figure.

135
00:07:33,000 --> 00:07:36,000
Okay I'm just going to probably give a print message.

136
00:07:36,000 --> 00:07:39,000
And this is basically present in the base class okay.

137
00:07:39,000 --> 00:07:42,000
Now what I will do I will go ahead and create my derived class.

138
00:07:42,000 --> 00:07:42,000
Now see this okay.

139
00:07:42,000 --> 00:07:46,000
Again I here I'll also be implementing function overriding okay.

140
00:07:46,000 --> 00:07:49,000
So this will be my derived class one okay.

141
00:07:49,000 --> 00:07:52,000
Let's say that I'm going to probably create a rectangle rectangle.

142
00:07:52,000 --> 00:07:57,000
And you know rectangle will inherit shape okay.

143
00:07:57,000 --> 00:08:02,000
And you know if for rectangle definitely what we require in order to calculate the area, it is nothing

144
00:08:02,000 --> 00:08:03,000
but width and height.

145
00:08:03,000 --> 00:08:06,000
So I'm just going to create my init method.

146
00:08:06,000 --> 00:08:12,000
And here I'm going to give self comma width comma height.

147
00:08:12,000 --> 00:08:15,000
This is what I'm going to pass in the runtime.

148
00:08:15,000 --> 00:08:16,000
I will go inside this.

149
00:08:16,000 --> 00:08:19,000
Now let me just go ahead and create my parameters or attributes.

150
00:08:20,000 --> 00:08:22,000
That is nothing but self dot width.

151
00:08:22,000 --> 00:08:24,000
Self dot height.

152
00:08:24,000 --> 00:08:27,000
And then we'll go to the next sentence.

153
00:08:28,000 --> 00:08:28,000
Oh sorry.

154
00:08:28,000 --> 00:08:31,000
This should be assigned to width.

155
00:08:32,000 --> 00:08:32,000
Okay.

156
00:08:32,000 --> 00:08:36,000
Then we will go ahead with self dot height which will be my another attribute.

157
00:08:36,000 --> 00:08:39,000
And this I will assign it to my height okay.

158
00:08:39,000 --> 00:08:42,000
Now I will go ahead and call this area function.

159
00:08:42,000 --> 00:08:42,000
Right.

160
00:08:42,000 --> 00:08:50,000
Now here what I am doing I am again I'm overriding this area method because the functionality will be

161
00:08:50,000 --> 00:08:51,000
little bit different over here.

162
00:08:51,000 --> 00:08:51,000
Right.

163
00:08:51,000 --> 00:08:53,000
How to calculate a area of a rectangle.

164
00:08:53,000 --> 00:08:57,000
It is nothing but just return self dot width.

165
00:08:57,000 --> 00:08:59,000
Self dot width.

166
00:09:00,000 --> 00:09:04,000
multiplied by self dot height.

167
00:09:05,000 --> 00:09:07,000
Self dot height.

168
00:09:08,000 --> 00:09:08,000
Right.

169
00:09:08,000 --> 00:09:10,000
This is what we are specifically doing.

170
00:09:10,000 --> 00:09:13,000
Now let me just go ahead and call the derived class two.

171
00:09:14,000 --> 00:09:19,000
Okay so here we have completely redefined or we have overridden the entire function.

172
00:09:19,000 --> 00:09:20,000
Right.

173
00:09:20,000 --> 00:09:27,000
So it's like all the function are basically having multiple forms as we keep on, uh, making sure that

174
00:09:27,000 --> 00:09:32,000
once our derived class inherits the parent class, we are basically redefining this entire function

175
00:09:32,000 --> 00:09:33,000
or we are overriding the functionality.

176
00:09:33,000 --> 00:09:34,000
Okay.

177
00:09:34,000 --> 00:09:37,000
Now let me just go ahead and create another derived class.

178
00:09:37,000 --> 00:09:40,000
And this time I'm going to create it as circle.

179
00:09:40,000 --> 00:09:41,000
Okay.

180
00:09:41,000 --> 00:09:44,000
This will again inherit shape okay.

181
00:09:44,000 --> 00:09:45,000
Shape.

182
00:09:45,000 --> 00:09:47,000
So let me just go ahead and inherit shape.

183
00:09:47,000 --> 00:09:54,000
And now this time, you know, I'll be using an init function and this will be a constructor.

184
00:09:54,000 --> 00:10:00,000
And here what I require in order to calculate the in order to calculate the area of a circle I just

185
00:10:00,000 --> 00:10:01,000
require radius.

186
00:10:01,000 --> 00:10:01,000
Right.

187
00:10:01,000 --> 00:10:06,000
So here I'm basically going to write self comma radius okay.

188
00:10:06,000 --> 00:10:11,000
Now let me just go ahead and write self dot radius is equal to radius right.

189
00:10:12,000 --> 00:10:17,000
So here you will be able to see that I have able to just get this particular parameter.

190
00:10:17,000 --> 00:10:24,000
I am able to create it now here also the area definition will be the function will be different right.

191
00:10:24,000 --> 00:10:26,000
So how do I calculate the area over here.

192
00:10:26,000 --> 00:10:28,000
I will just say return right.

193
00:10:28,000 --> 00:10:30,000
It is nothing but pi r square right?

194
00:10:30,000 --> 00:10:42,000
Pi is nothing but 3.14 multiplied by the radius into sorry self dot radius self dot radius multiplied

195
00:10:42,000 --> 00:10:46,000
by self dot radius pi r square.

196
00:10:46,000 --> 00:10:46,000
Right.

197
00:10:47,000 --> 00:10:48,000
Done.

198
00:10:48,000 --> 00:10:51,000
And this will basically give me the area.

199
00:10:51,000 --> 00:11:01,000
Now what I will do along with this, I will just go ahead and write a function that demonstrates polymorphism.

200
00:11:03,000 --> 00:11:05,000
And here is what I will be writing.

201
00:11:05,000 --> 00:11:08,000
So here let me just go ahead and write print underscore area.

202
00:11:08,000 --> 00:11:16,000
And here I'm actually going to give me give the shape which will be an object okay of a specific class.

203
00:11:16,000 --> 00:11:20,000
And we will just go ahead and print with my f string.

204
00:11:20,000 --> 00:11:27,000
The area is nothing but shape dot area.

205
00:11:27,000 --> 00:11:30,000
Right shape dot area.

206
00:11:30,000 --> 00:11:31,000
Which will be my function.

207
00:11:31,000 --> 00:11:32,000
Okay.

208
00:11:32,000 --> 00:11:34,000
Now this is what we are going to just print it.

209
00:11:34,000 --> 00:11:34,000
Right.

210
00:11:34,000 --> 00:11:36,000
Now let me just go ahead and create the objects.

211
00:11:36,000 --> 00:11:40,000
So first of all what I'm actually going to do I'm going to create a rectangle object.

212
00:11:40,000 --> 00:11:43,000
Go ahead and use rectangle right.

213
00:11:43,000 --> 00:11:45,000
Basically use four comma five.

214
00:11:46,000 --> 00:11:49,000
In case of circle I just need to provide my radius.

215
00:11:49,000 --> 00:11:53,000
So let me just go ahead and define circle with radius.

216
00:11:53,000 --> 00:11:54,000
Radius is let's say three.

217
00:11:55,000 --> 00:12:01,000
Now if I want to go ahead and just call the area function I will just go ahead and write print underscore

218
00:12:01,000 --> 00:12:02,000
area.

219
00:12:02,000 --> 00:12:05,000
And I will give the object that is rectangle.

220
00:12:05,000 --> 00:12:07,000
Okay rectangle.

221
00:12:07,000 --> 00:12:14,000
And similarly I will go ahead and call print underscore area where I will be giving circle right.

222
00:12:14,000 --> 00:12:16,000
And this is how we execute it.

223
00:12:16,000 --> 00:12:19,000
And here you can see the area okay.

224
00:12:19,000 --> 00:12:23,000
The area is 20 and 28.25.

225
00:12:23,000 --> 00:12:30,000
So this is the area with respect to uh, you know uh the, the, the, the, the area of the rectangle

226
00:12:30,000 --> 00:12:32,000
which we basically write length into breadth.

227
00:12:32,000 --> 00:12:34,000
So nothing but four into five.

228
00:12:34,000 --> 00:12:36,000
And if I go ahead and calculate pi r square.

229
00:12:36,000 --> 00:12:38,000
So I'm actually going to get 28.25.

230
00:12:38,000 --> 00:12:39,000
Right.

231
00:12:39,000 --> 00:12:40,000
So this is one amazing example.

232
00:12:40,000 --> 00:12:43,000
And here you can see that we have used functions.

233
00:12:43,000 --> 00:12:47,000
We have defined another function that demonstrates polymorphism over here.

234
00:12:47,000 --> 00:12:51,000
And uh this is one of the amazing example with respect to this okay.

235
00:12:52,000 --> 00:12:57,000
And here also we are basically playing with the same method name but with different different definition.

236
00:12:57,000 --> 00:12:57,000
Okay.

237
00:12:57,000 --> 00:13:03,000
Now let me just, uh, introduce you to see, uh, I've already written over here something like this.

238
00:13:03,000 --> 00:13:04,000
Right.

239
00:13:04,000 --> 00:13:09,000
Um, polymorphism is typically achieved through method overriding and interfaces.

240
00:13:09,000 --> 00:13:10,000
Now let's talk about this.

241
00:13:10,000 --> 00:13:11,000
Interfaces.

242
00:13:11,000 --> 00:13:15,000
What is interfaces in other programming languages we basically say interfaces in Python.

243
00:13:16,000 --> 00:13:19,000
We say it as abstract base class.

244
00:13:19,000 --> 00:13:21,000
Now what exactly it is.

245
00:13:21,000 --> 00:13:22,000
Let's discuss about it.

246
00:13:22,000 --> 00:13:28,000
So polymorphism with abstract base classes Okay.

247
00:13:29,000 --> 00:13:31,000
Now abstract base class.

248
00:13:31,000 --> 00:13:34,000
Uh, if I really want to define it.

249
00:13:34,000 --> 00:13:34,000
Okay.

250
00:13:35,000 --> 00:13:36,000
It's very simple.

251
00:13:36,000 --> 00:13:38,000
Let's go ahead and see the definition.

252
00:13:38,000 --> 00:13:40,000
I'll paste it over here.

253
00:13:40,000 --> 00:13:42,000
And let me just go ahead and write this okay.

254
00:13:43,000 --> 00:13:45,000
Uh, important topic altogether.

255
00:13:45,000 --> 00:13:46,000
Okay.

256
00:13:47,000 --> 00:13:53,000
Abstract base class are used to define common methods for a group of related objects.

257
00:13:53,000 --> 00:13:58,000
They can enforce that derived class, implement a particular method promoting consistency across the

258
00:13:58,000 --> 00:14:00,000
different implementation.

259
00:14:00,000 --> 00:14:02,000
Okay, so abstract base class.

260
00:14:02,000 --> 00:14:04,000
That is the reason we say it as ABC.

261
00:14:04,000 --> 00:14:06,000
Okay let's do one thing okay.

262
00:14:06,000 --> 00:14:08,000
Let's let's show you an example over here.

263
00:14:09,000 --> 00:14:12,000
Uh I will be defining two important things.

264
00:14:12,000 --> 00:14:14,000
First I will write from ABC.

265
00:14:14,000 --> 00:14:15,000
Okay.

266
00:14:15,000 --> 00:14:16,000
Now what is this ABC?

267
00:14:16,000 --> 00:14:18,000
We are basically using abstract base class.

268
00:14:18,000 --> 00:14:21,000
We are going to import ABC.

269
00:14:21,000 --> 00:14:21,000
Okay.

270
00:14:21,000 --> 00:14:26,000
Along with that we will be importing abstract method okay.

271
00:14:26,000 --> 00:14:31,000
This abstract method is a kind of decorator okay I'll be talking about what exactly is decorator as

272
00:14:31,000 --> 00:14:32,000
we go ahead.

273
00:14:32,000 --> 00:14:32,000
Right.

274
00:14:32,000 --> 00:14:37,000
But just consider right now this is what, uh, abstract class is all about.

275
00:14:37,000 --> 00:14:41,000
You know, it is it is just like it is just used to define a common methods.

276
00:14:41,000 --> 00:14:42,000
Okay.

277
00:14:42,000 --> 00:14:45,000
So I will just go ahead and define an abstract class.

278
00:14:45,000 --> 00:14:47,000
How do I define an abstract class.

279
00:14:47,000 --> 00:14:49,000
This is what I'm going to show you.

280
00:14:49,000 --> 00:14:50,000
Abstract class okay.

281
00:14:51,000 --> 00:14:56,000
Now um abstract class here I'll say hey, uh, let's create a class called as vehicle.

282
00:14:56,000 --> 00:14:57,000
Okay.

283
00:14:57,000 --> 00:15:02,000
And this I'm going to inherit to the abstract class, which will be like an empty class itself.

284
00:15:02,000 --> 00:15:03,000
Right?

285
00:15:03,000 --> 00:15:04,000
So, uh.

286
00:15:05,000 --> 00:15:09,000
this abstract class, afterwards, I define it, I will be defining abstract method.

287
00:15:09,000 --> 00:15:15,000
Also see, in order to just give you a simple definition of abstract class, it is like a complete empty

288
00:15:15,000 --> 00:15:15,000
class.

289
00:15:15,000 --> 00:15:19,000
You know, there, uh, if you are defining also method, it will be initially empty.

290
00:15:19,000 --> 00:15:20,000
Okay.

291
00:15:20,000 --> 00:15:24,000
So that is the reason why we have written that abstract base classes are used to define common methods

292
00:15:24,000 --> 00:15:25,000
for a group of related objects.

293
00:15:25,000 --> 00:15:28,000
Here no definition will be there much.

294
00:15:28,000 --> 00:15:28,000
Okay.

295
00:15:28,000 --> 00:15:32,000
So, uh, with respect to this, uh, now I have created this particular class.

296
00:15:32,000 --> 00:15:37,000
I'm not putting any information, but let me just go ahead and create an abstract method.

297
00:15:37,000 --> 00:15:37,000
Okay?

298
00:15:37,000 --> 00:15:41,000
Abstract method is just like an empty method, but it is kind of common class.

299
00:15:41,000 --> 00:15:46,000
That is probably going to happen in each and every class, because we are going to inherit this kind

300
00:15:46,000 --> 00:15:47,000
of abstract class onto this.

301
00:15:47,000 --> 00:15:48,000
Right.

302
00:15:48,000 --> 00:15:52,000
So here what I'm going to write, I'll just go ahead and write define start engine.

303
00:15:52,000 --> 00:15:56,000
So this will basically be my function.

304
00:15:56,000 --> 00:15:58,000
And here I'm going to use my self keyword.

305
00:15:58,000 --> 00:16:01,000
And since it is abstract it needs to be empty.

306
00:16:01,000 --> 00:16:03,000
So I am going to just write pass okay.

307
00:16:03,000 --> 00:16:06,000
So this is how I have actually created my abstract class.

308
00:16:06,000 --> 00:16:10,000
Along with that I am also creating my abstract method called as Start Engine.

309
00:16:10,000 --> 00:16:14,000
Now what I will do for my derived class one I will inherit this.

310
00:16:14,000 --> 00:16:19,000
Okay, so let me just take class car And here I'm just going to use vehicle okay.

311
00:16:20,000 --> 00:16:24,000
Now you know that I have defined my abstract method which is completely empty.

312
00:16:24,000 --> 00:16:29,000
Now I can since I'm inheriting vehicle, I'll also be inheriting this particular method and I can define

313
00:16:29,000 --> 00:16:29,000
my own function.

314
00:16:29,000 --> 00:16:35,000
So that is the reason we'll go ahead and write definition start underscore engine okay.

315
00:16:35,000 --> 00:16:37,000
Start underscore engine self.

316
00:16:37,000 --> 00:16:44,000
And we are just going to return over here Car engine started okay.

317
00:16:44,000 --> 00:16:45,000
Some information.

318
00:16:45,000 --> 00:16:47,000
Car engine started.

319
00:16:47,000 --> 00:16:47,000
Okay.

320
00:16:47,000 --> 00:16:51,000
And here you can define your own init method also inside this particular class also.

321
00:16:51,000 --> 00:16:51,000
Right.

322
00:16:51,000 --> 00:16:54,000
Define any number of parameters that you want okay.

323
00:16:54,000 --> 00:17:00,000
Now uh similarly if I go ahead and create my derived class two, you'll be seeing hey, let's go ahead

324
00:17:00,000 --> 00:17:04,000
and create this particular class called as Motor cycle.

325
00:17:04,000 --> 00:17:05,000
Okay.

326
00:17:05,000 --> 00:17:09,000
And here I'm actually going to give my vehicle okay vehicle class.

327
00:17:09,000 --> 00:17:11,000
And let's go ahead and inherit it.

328
00:17:11,000 --> 00:17:22,000
And uh if I go ahead and write definition start underscore engine here I'm just going to return motorcycle

329
00:17:22,000 --> 00:17:27,000
dot sorry motorcycle engine started.

330
00:17:30,000 --> 00:17:35,000
So here you can see this function is having a different definition inside motor class motorcycle class.

331
00:17:35,000 --> 00:17:38,000
And it has a different definition inside the child class.

332
00:17:38,000 --> 00:17:43,000
Okay then uh let me just go ahead and create the object of the class.

333
00:17:43,000 --> 00:17:50,000
So create objects of car and motorcycle.

334
00:17:52,000 --> 00:17:56,000
Now see I will just go ahead and create it.

335
00:17:57,000 --> 00:17:58,000
Okay.

336
00:17:58,000 --> 00:18:00,000
And we can do the same implementation like this also.

337
00:18:00,000 --> 00:18:00,000
Right.

338
00:18:00,000 --> 00:18:02,000
So I have inherited over here.

339
00:18:02,000 --> 00:18:06,000
Let me just go ahead and define one function that will demonstrate my entire polymorphism.

340
00:18:08,000 --> 00:18:14,000
And now I can just go ahead and start this vehicle and just let me define my car.

341
00:18:14,000 --> 00:18:19,000
And if I go ahead and execute it, you can see that automatically it is being able to call this called

342
00:18:19,000 --> 00:18:20,000
as uh, start engine.

343
00:18:20,000 --> 00:18:22,000
And here we are able to display it.

344
00:18:22,000 --> 00:18:26,000
So here I have actually shown you polymorphism with the help of method overriding.

345
00:18:26,000 --> 00:18:29,000
Along with that we have also seen with the help of abstract class.

346
00:18:29,000 --> 00:18:31,000
So this two you definitely need to know.

347
00:18:31,000 --> 00:18:38,000
And uh, again uh, ending this session I will try to provide some conclusion which is a good habit.

348
00:18:38,000 --> 00:18:39,000
Okay.

349
00:18:39,000 --> 00:18:44,000
So here with respect to the conclusion, you should know why polymorphism is important.

350
00:18:44,000 --> 00:18:47,000
It is a powerful feature that allows the flexibility and integration in code design.

351
00:18:47,000 --> 00:18:52,000
It enables a single function to handle objects a different class, each with its own implementation

352
00:18:52,000 --> 00:18:53,000
of a method.

353
00:18:53,000 --> 00:18:57,000
By understanding applying polymorphism, you can create extensible and maintainable object oriented

354
00:18:57,000 --> 00:18:58,000
programs.

355
00:18:58,000 --> 00:19:03,000
Okay, but here we are just seeing that what all features it has with respect to polymorphism.

356
00:19:03,000 --> 00:19:03,000
Right.

357
00:19:03,000 --> 00:19:05,000
So yes this was it for my side.

358
00:19:05,000 --> 00:19:06,000
I hope you like this particular video.

359
00:19:06,000 --> 00:19:08,000
I'll see you all in the next video.

360
00:19:08,000 --> 00:19:08,000
Thank you.

361
00:19:08,000 --> 00:19:08,000
Take care.

