1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:03,000
So we are going to continue our discussion with respect to Python.

3
00:00:03,000 --> 00:00:06,000
And in this video we are going to discuss about inheritance in Python.

4
00:00:06,000 --> 00:00:13,000
Now this inheritance is a fundamental concept in object oriented programming that allows a class to

5
00:00:13,000 --> 00:00:17,000
inherit attributes and methods from another class, right.

6
00:00:17,000 --> 00:00:21,000
So in this specific video I will be talking about how you can implement inheritance.

7
00:00:21,000 --> 00:00:22,000
With the help of Python.

8
00:00:22,000 --> 00:00:25,000
We'll be discussing about single inheritance and multiple inheritance.

9
00:00:25,000 --> 00:00:27,000
And I'll be showing you multiple examples.

10
00:00:27,000 --> 00:00:29,000
So let's go ahead and let's see.

11
00:00:29,000 --> 00:00:33,000
Now inheritance is basically derived from the real world scenario.

12
00:00:33,000 --> 00:00:39,000
Guys I hope uh, you know, like let's say uh, you will be inheriting your parents property.

13
00:00:39,000 --> 00:00:43,000
You know, it may be house, it may be land, you know, but the vice versa will not be possible.

14
00:00:43,000 --> 00:00:49,000
You know, you your parent will basically not be inheriting your property, but instead it will be going

15
00:00:49,000 --> 00:00:50,000
to your children.

16
00:00:50,000 --> 00:00:50,000
Right?

17
00:00:50,000 --> 00:00:51,000
So this kind of scenario.

18
00:00:51,000 --> 00:00:53,000
So this is based on the real world scenario.

19
00:00:53,000 --> 00:00:57,000
And similarly the inheritance property in Python also works in the same way.

20
00:00:57,000 --> 00:00:58,000
Okay.

21
00:00:58,000 --> 00:01:02,000
So let me just go ahead and show you one specific example of inheritance.

22
00:01:02,000 --> 00:01:08,000
And then I will show you how you can probably create a child class and probably inherit the parent class

23
00:01:08,000 --> 00:01:08,000
altogether.

24
00:01:08,000 --> 00:01:09,000
Right.

25
00:01:09,000 --> 00:01:12,000
So I will first of all start defining my parent class.

26
00:01:12,000 --> 00:01:13,000
Okay.

27
00:01:13,000 --> 00:01:17,000
Now here, let me just go ahead and define one class which is called as car.

28
00:01:17,000 --> 00:01:17,000
Okay.

29
00:01:18,000 --> 00:01:21,000
Now car is my class okay.

30
00:01:21,000 --> 00:01:23,000
So I can also go ahead and write like this okay.

31
00:01:23,000 --> 00:01:24,000
Class car.

32
00:01:24,000 --> 00:01:30,000
Now first of all, as you all know, whenever we define a class we need to probably create a constructor.

33
00:01:30,000 --> 00:01:34,000
So let's go ahead and create this underscore underscore init underscore underscore.

34
00:01:34,000 --> 00:01:37,000
And here I'm going to use one parameter that is self.

35
00:01:37,000 --> 00:01:43,000
And uh the other parameters that we are going to provide while we are instantiating the object of the

36
00:01:43,000 --> 00:01:49,000
car class, you know, like windows, doors, right, engine type.

37
00:01:49,000 --> 00:01:53,000
So let's consider that these are some of the attributes that we are going to pass.

38
00:01:53,000 --> 00:01:56,000
And let's go ahead and create some of the instance variable.

39
00:01:56,000 --> 00:01:58,000
So I will go ahead and write self dot.

40
00:01:58,000 --> 00:02:03,000
And the first thing is that windows right I will go ahead and create the first attribute that is windows.

41
00:02:03,000 --> 00:02:08,000
And I'll assign this value to the windows that I'm passing over here in this init method.

42
00:02:08,000 --> 00:02:08,000
Okay.

43
00:02:08,000 --> 00:02:12,000
Then we will go ahead and write self dot doors okay.

44
00:02:12,000 --> 00:02:14,000
Where I will be passing the doors value.

45
00:02:14,000 --> 00:02:19,000
And finally I will go ahead and write self dot engine type okay engine type.

46
00:02:19,000 --> 00:02:23,000
And again I've already told you it need not be this name need not be same as this.

47
00:02:23,000 --> 00:02:27,000
You can write anything over here but these are the attributes or instance variable right.

48
00:02:27,000 --> 00:02:28,000
So is equal to.

49
00:02:28,000 --> 00:02:31,000
We will go ahead and write engine type okay.

50
00:02:31,000 --> 00:02:33,000
Now this is my car class.

51
00:02:33,000 --> 00:02:36,000
And this is what I have in terms of attributes and all.

52
00:02:36,000 --> 00:02:39,000
Let me just go ahead and define one instance method.

53
00:02:39,000 --> 00:02:43,000
Also let's say with the help of class car we usually drive.

54
00:02:43,000 --> 00:02:47,000
So here what I'm actually going to do is that I'll go ahead and use self keyword okay.

55
00:02:47,000 --> 00:02:49,000
And let me just go ahead and print okay.

56
00:02:50,000 --> 00:02:56,000
And let me say that uh, the the car, the person will drive the car.

57
00:02:56,000 --> 00:03:01,000
The person will drive the which car?

58
00:03:01,000 --> 00:03:05,000
Okay, so let's say that the person will drive the petrol car or engine type car, right.

59
00:03:05,000 --> 00:03:09,000
So here I will just go ahead and write engine type okay.

60
00:03:09,000 --> 00:03:13,000
And here I'm actually going to use this f string okay.

61
00:03:13,000 --> 00:03:14,000
Engine type.

62
00:03:14,000 --> 00:03:18,000
Now engine type I cannot directly use it over here because I have to use self dot right.

63
00:03:18,000 --> 00:03:20,000
Because engine type is an attribute over here, right?

64
00:03:20,000 --> 00:03:23,000
So the person will drive the engine type car.

65
00:03:23,000 --> 00:03:24,000
Okay.

66
00:03:24,000 --> 00:03:28,000
And I have to probably if I want to use this attribute over here I have to use self dot okay.

67
00:03:28,000 --> 00:03:31,000
So inside this this is my parent class okay.

68
00:03:31,000 --> 00:03:33,000
I've defined a class with an init method.

69
00:03:33,000 --> 00:03:39,000
The attributes are windows doors and engine type and one instance method which is called as drive.

70
00:03:39,000 --> 00:03:44,000
Uh, and here I'm saying that hey, the person will drive whether it can be a petrol car or diesel car

71
00:03:44,000 --> 00:03:46,000
based on the values that we provide right now.

72
00:03:46,000 --> 00:03:50,000
Once I probably go ahead and create this class, let's consider this is my parent class.

73
00:03:50,000 --> 00:03:54,000
Now I can go ahead and write car one is equal to.

74
00:03:54,000 --> 00:03:56,000
I will go ahead and define my car okay.

75
00:03:56,000 --> 00:03:58,000
And here I'm going to give the values.

76
00:03:58,000 --> 00:03:59,000
Let's say number of windows are four.

77
00:03:59,000 --> 00:04:01,000
Number of doors are five.

78
00:04:01,000 --> 00:04:04,000
And let's consider the engine type is petrol okay.

79
00:04:05,000 --> 00:04:07,000
Petrol Petrol car okay.

80
00:04:08,000 --> 00:04:13,000
And now I will go ahead and print car one dot.

81
00:04:13,000 --> 00:04:15,000
The method that is drive right.

82
00:04:15,000 --> 00:04:18,000
Now if I go ahead and execute it here you'll be able to see that.

83
00:04:18,000 --> 00:04:24,000
Hey the person the person will drive the petrol car and obviously drive does not return anything over

84
00:04:24,000 --> 00:04:24,000
here.

85
00:04:24,000 --> 00:04:26,000
So that is the reason it is giving you none.

86
00:04:26,000 --> 00:04:26,000
Okay.

87
00:04:26,000 --> 00:04:31,000
But uh, in short, over here you can see that I'm just writing, uh, car one dot drive.

88
00:04:31,000 --> 00:04:33,000
So it is just going to display this.

89
00:04:33,000 --> 00:04:34,000
The person will drive the car.

90
00:04:34,000 --> 00:04:36,000
Okay, perfect.

91
00:04:36,000 --> 00:04:40,000
Uh, if I just remove the print method, then you will be able to see that I'll be able to get only

92
00:04:40,000 --> 00:04:41,000
one message.

93
00:04:41,000 --> 00:04:41,000
Okay?

94
00:04:41,000 --> 00:04:42,000
That is print.

95
00:04:42,000 --> 00:04:46,000
The person will drive the petrol car because this drive method is not returning anything.

96
00:04:46,000 --> 00:04:48,000
But this is fine, right?

97
00:04:48,000 --> 00:04:49,000
Uh, this is very much easy.

98
00:04:49,000 --> 00:04:51,000
And here you can actually see that what?

99
00:04:51,000 --> 00:04:52,000
All things we have basically done.

100
00:04:52,000 --> 00:04:52,000
Right.

101
00:04:52,000 --> 00:04:57,000
We have given a car class, and probably we have defined the init method.

102
00:04:57,000 --> 00:04:59,000
We have defined a method over here.

103
00:04:59,000 --> 00:04:59,000
Right.

104
00:04:59,000 --> 00:05:01,000
And we are able to create the objects.

105
00:05:01,000 --> 00:05:01,000
Right.

106
00:05:01,000 --> 00:05:02,000
This is perfect.

107
00:05:02,000 --> 00:05:04,000
Now let me do one thing.

108
00:05:04,000 --> 00:05:07,000
Now see there are different types of cars.

109
00:05:07,000 --> 00:05:07,000
Right.

110
00:05:07,000 --> 00:05:11,000
Uh, I can just consider this car class is a blueprint of a car object, right?

111
00:05:11,000 --> 00:05:12,000
It is.

112
00:05:12,000 --> 00:05:17,000
This is the blueprint where it has this many number of attributes, this many number of methods.

113
00:05:17,000 --> 00:05:20,000
Now, let me just go ahead and create one class which is called as Tesla.

114
00:05:20,000 --> 00:05:21,000
Okay.

115
00:05:21,000 --> 00:05:27,000
Now this Tesla car that you are probably seeing over here, obviously it needs to inherit from the class

116
00:05:27,000 --> 00:05:28,000
car blueprint itself, right.

117
00:05:28,000 --> 00:05:34,000
Because in this Tesla also I will be having windows, I will be having windows, I will be having doors.

118
00:05:34,000 --> 00:05:36,000
I will be having engine type.

119
00:05:36,000 --> 00:05:36,000
Right.

120
00:05:36,000 --> 00:05:40,000
And there may be some additional feature that may be available in Tesla.

121
00:05:40,000 --> 00:05:44,000
So I don't have to again, go ahead and define this entire thing instead.

122
00:05:44,000 --> 00:05:49,000
What I can do, I can just inherit this car class and I can inherit this properties along with I can

123
00:05:49,000 --> 00:05:51,000
inherit this functions or methods.

124
00:05:51,000 --> 00:05:52,000
Right?

125
00:05:52,000 --> 00:05:57,000
Because I don't have to recreate the entire class completely from scratch if it is inheriting this particular

126
00:05:57,000 --> 00:06:03,000
car class, which is a blueprint, it will be able to inherit all these attributes and methods, right.

127
00:06:03,000 --> 00:06:04,000
So let's go ahead and do this.

128
00:06:04,000 --> 00:06:08,000
So in order to make Tesla inherit car.

129
00:06:08,000 --> 00:06:10,000
So I will just go ahead and write over here as car.

130
00:06:10,000 --> 00:06:12,000
So this is how you basically write.

131
00:06:12,000 --> 00:06:16,000
First of all you really need to write your child class like class Tesla.

132
00:06:16,000 --> 00:06:21,000
And then whatever things you basically write in the bracket, this is basically inheriting that particular

133
00:06:21,000 --> 00:06:21,000
class.

134
00:06:21,000 --> 00:06:22,000
Okay.

135
00:06:22,000 --> 00:06:28,000
Now we will again go ahead with defining our init function because here also we'll be having an init

136
00:06:28,000 --> 00:06:29,000
function right.

137
00:06:29,000 --> 00:06:31,000
So definition underscore underscore init underscore underscore.

138
00:06:31,000 --> 00:06:33,000
So this is my constructor inside the Tesla.

139
00:06:33,000 --> 00:06:39,000
And you know here also we require attributes like windows doors okay.

140
00:06:39,000 --> 00:06:41,000
So we need to pass it during the runtime.

141
00:06:41,000 --> 00:06:43,000
Then you have engine type.

142
00:06:43,000 --> 00:06:47,000
And finally these all attributes are already available over here.

143
00:06:47,000 --> 00:06:47,000
Right.

144
00:06:47,000 --> 00:06:51,000
So they may be additional attributes that may be available in Tesla.

145
00:06:51,000 --> 00:06:54,000
So I will just go ahead and say is self-driving okay.

146
00:06:54,000 --> 00:06:56,000
And this will be a boolean value.

147
00:06:56,000 --> 00:06:57,000
Let's consider this okay.

148
00:06:57,000 --> 00:06:58,000
It's self-driving.

149
00:06:58,000 --> 00:07:02,000
So Tesla you know that it has a self-driving functionalities okay.

150
00:07:02,000 --> 00:07:04,000
Now fine.

151
00:07:04,000 --> 00:07:10,000
Now the main thing is that I need to create the attributes for windows, doors and engine type.

152
00:07:10,000 --> 00:07:13,000
And I know that car already has this kind of attributes.

153
00:07:13,000 --> 00:07:14,000
Right.

154
00:07:14,000 --> 00:07:16,000
So I don't need to go ahead and write self dot write.

155
00:07:16,000 --> 00:07:21,000
What I can do is that I can just use this super keyword, right?

156
00:07:21,000 --> 00:07:28,000
If I use the super keyword, that basically means I'm saying, hey, I'm trying to call the see super

157
00:07:28,000 --> 00:07:31,000
basically means I'm just trying to call the parent class over here.

158
00:07:31,000 --> 00:07:35,000
And from the parent class, I will just go ahead and call my init method.

159
00:07:35,000 --> 00:07:36,000
Okay.

160
00:07:36,000 --> 00:07:39,000
So here what does super underscore init basically mean.

161
00:07:39,000 --> 00:07:42,000
That basically means that we are just calling this init method from the car class.

162
00:07:42,000 --> 00:07:43,000
Right.

163
00:07:43,000 --> 00:07:44,000
Parent class.

164
00:07:44,000 --> 00:07:44,000
Right.

165
00:07:44,000 --> 00:07:47,000
And that is the reason we are just writing super dot underscore underscore init.

166
00:07:48,000 --> 00:07:54,000
Now over here the next step will be that you know what all attributes I'll be getting from the parent

167
00:07:54,000 --> 00:07:55,000
class.

168
00:07:55,000 --> 00:07:57,000
One is windows.

169
00:07:57,000 --> 00:07:58,000
Okay.

170
00:07:58,000 --> 00:08:00,000
So let me just go ahead and write windows doors.

171
00:08:01,000 --> 00:08:03,000
And then you have this engine type right.

172
00:08:03,000 --> 00:08:05,000
Then you have this engine type.

173
00:08:05,000 --> 00:08:09,000
So this three values or attributes I should be getting from this car class.

174
00:08:09,000 --> 00:08:09,000
Right.

175
00:08:09,000 --> 00:08:11,000
So I don't have to again define it.

176
00:08:11,000 --> 00:08:13,000
But what about my cell is self driving.

177
00:08:13,000 --> 00:08:18,000
So I will just go ahead and write self dot is self driving okay.

178
00:08:18,000 --> 00:08:21,000
So let me just go ahead and create this variable.

179
00:08:21,000 --> 00:08:23,000
Self dot is self driving.

180
00:08:23,000 --> 00:08:24,000
Oops.

181
00:08:24,000 --> 00:08:29,000
Self dot is self driving and I will assign it to is dot self driving.

182
00:08:29,000 --> 00:08:36,000
So this is the attribute and this only attribute will try to create inside the Tesla class okay.

183
00:08:36,000 --> 00:08:42,000
And remaining all we are in short inheriting from the parent class right now when we are inheriting

184
00:08:42,000 --> 00:08:43,000
this.

185
00:08:43,000 --> 00:08:47,000
Obviously it is true that we will also be able to inherit this two, right?

186
00:08:47,000 --> 00:08:48,000
So let's see this okay.

187
00:08:48,000 --> 00:08:53,000
Now I will go ahead and probably I've created my init method over here.

188
00:08:53,000 --> 00:08:59,000
And uh now what I will do I will create another function which supports self driving.

189
00:08:59,000 --> 00:09:00,000
Right?

190
00:09:00,000 --> 00:09:02,000
Let's say self driving.

191
00:09:02,000 --> 00:09:05,000
So here I'm just going to write self driving.

192
00:09:07,000 --> 00:09:10,000
And here I'm going to say self okay.

193
00:09:11,000 --> 00:09:11,000
Perfect.

194
00:09:12,000 --> 00:09:12,000
Right.

195
00:09:12,000 --> 00:09:17,000
So this is the method or this is the instance method that we are going to create inside this Tesla cars.

196
00:09:17,000 --> 00:09:21,000
Uh which is the additional thing when compared to the uh, class blueprint.

197
00:09:21,000 --> 00:09:22,000
Car blueprint.

198
00:09:22,000 --> 00:09:22,000
Sorry.

199
00:09:23,000 --> 00:09:28,000
Now, here, I'm just going to, uh, print something and write over here.

200
00:09:28,000 --> 00:09:31,000
Uh, Tesla.

201
00:09:33,000 --> 00:09:34,000
Supports.

202
00:09:35,000 --> 00:09:35,000
Okay.

203
00:09:36,000 --> 00:09:39,000
I can just go ahead and write self dot is.

204
00:09:40,000 --> 00:09:41,000
So here I'm just going to use my f string.

205
00:09:41,000 --> 00:09:44,000
Always focus on using this f string.

206
00:09:44,000 --> 00:09:48,000
Then only you will be able to use this particular uh you'll be able to basically write in this way.

207
00:09:48,000 --> 00:09:51,000
So self dot is driving okay.

208
00:09:51,000 --> 00:09:55,000
So here you have this entire thing okay.

209
00:09:55,000 --> 00:09:58,000
Now Tesla supports self driving.

210
00:09:58,000 --> 00:10:00,000
True or not Tesla supports self driving.

211
00:10:00,000 --> 00:10:04,000
So here I'll say self driving.

212
00:10:04,000 --> 00:10:08,000
So this will basically give me a value like true or false okay.

213
00:10:08,000 --> 00:10:11,000
Now this is my entire Tesla car right?

214
00:10:11,000 --> 00:10:15,000
And this is my child class which is inheriting the car class.

215
00:10:15,000 --> 00:10:16,000
Right.

216
00:10:16,000 --> 00:10:19,000
Now once I execute this now let's go ahead and call this okay.

217
00:10:19,000 --> 00:10:23,000
So first of all I will just go ahead and write Tesla one variant and I will go ahead and initialize

218
00:10:23,000 --> 00:10:24,000
it.

219
00:10:24,000 --> 00:10:28,000
And now what all parameters I need to give windows doors and engine type.

220
00:10:28,000 --> 00:10:30,000
So I'll say hey windows are four.

221
00:10:30,000 --> 00:10:31,000
Doors are five.

222
00:10:31,000 --> 00:10:33,000
Engine type is electric.

223
00:10:33,000 --> 00:10:35,000
Let's say electric okay.

224
00:10:35,000 --> 00:10:39,000
And uh, whether the, uh, whether it supports self-driving or not, I'll just go ahead and write.

225
00:10:39,000 --> 00:10:39,000
True.

226
00:10:39,000 --> 00:10:40,000
Okay.

227
00:10:40,000 --> 00:10:47,000
Now, after giving all these parameters, you will be able to see that if I go ahead and print Tesla

228
00:10:47,000 --> 00:10:50,000
one dot self-driving.

229
00:10:50,000 --> 00:10:50,000
Okay.

230
00:10:50,000 --> 00:10:51,000
And I'll call this function.

231
00:10:51,000 --> 00:10:53,000
Let's see what it says.

232
00:10:53,000 --> 00:10:58,000
So here you will be able to see that it is printing Tesla supports self-driving is equal to true.

233
00:10:58,000 --> 00:10:59,000
And this is what we have given.

234
00:10:59,000 --> 00:11:04,000
So what happens once we call this particular child class with Tesla and all these values.

235
00:11:04,000 --> 00:11:05,000
What it is going to do.

236
00:11:05,000 --> 00:11:09,000
It will just go ahead and call super init and it will pass all these parameters over here.

237
00:11:09,000 --> 00:11:14,000
And this init will make sure that all the attributes, it will go ahead and initialize with those values

238
00:11:14,000 --> 00:11:16,000
like self, dot windows, door doors and engine type.

239
00:11:16,000 --> 00:11:18,000
Now once that is done then we'll go ahead and initialize.

240
00:11:18,000 --> 00:11:21,000
The attribute is underscore self driving which will be assigned to true.

241
00:11:21,000 --> 00:11:25,000
And then I can probably call this particular function not only this.

242
00:11:25,000 --> 00:11:28,000
Now in the parent class I have this drive function right.

243
00:11:28,000 --> 00:11:36,000
So I can also call that see I will go ahead and write test one dot drive function okay.

244
00:11:36,000 --> 00:11:40,000
If I go ahead and call this here, you can see the person will drive the electric car.

245
00:11:40,000 --> 00:11:40,000
Right.

246
00:11:40,000 --> 00:11:45,000
And this is how you can probably see that a single inheritance works like.

247
00:11:45,000 --> 00:11:46,000
Right.

248
00:11:46,000 --> 00:11:47,000
And, uh.

249
00:11:47,000 --> 00:11:50,000
Uh, you understood the main mechanism.

250
00:11:50,000 --> 00:11:54,000
If you really want to inherit any parent class, how you have to probably use this init method, how

251
00:11:54,000 --> 00:11:59,000
you have to call the super init method, how to define the new attributes, how to initialize those

252
00:11:59,000 --> 00:12:02,000
new attributes over here, you know, during the runtime.

253
00:12:02,000 --> 00:12:06,000
And along with that, you can actually go ahead and create any more methods that you want.

254
00:12:06,000 --> 00:12:07,000
Okay.

255
00:12:07,000 --> 00:12:12,000
And this is what is an example with respect to inheritance and this inheritance, I will just say it

256
00:12:12,000 --> 00:12:18,000
as single inheritance because, uh, only one child class is inheriting the parent class.

257
00:12:18,000 --> 00:12:18,000
Okay.

258
00:12:18,000 --> 00:12:25,000
Now let me just, uh, show you an example with respect to multiple inheritance, but I hope you are

259
00:12:25,000 --> 00:12:26,000
able to understand.

260
00:12:26,000 --> 00:12:31,000
Okay, so here will be multiple inheritance okay.

261
00:12:31,000 --> 00:12:33,000
Now multiple inheritance means what?

262
00:12:34,000 --> 00:12:35,000
When a class.

263
00:12:36,000 --> 00:12:45,000
When a class inherits from more than one base class.

264
00:12:45,000 --> 00:12:46,000
Okay.

265
00:12:46,000 --> 00:12:50,000
When a class inherits more than one base class.

266
00:12:50,000 --> 00:12:50,000
Okay.

267
00:12:50,000 --> 00:12:52,000
Now what does this basically mean?

268
00:12:52,000 --> 00:12:54,000
Let's go ahead and create one base class okay.

269
00:12:54,000 --> 00:12:58,000
Let's say I will go ahead and create animal okay.

270
00:12:58,000 --> 00:13:00,000
So animal is one class okay.

271
00:13:00,000 --> 00:13:03,000
And here I'm just going to use my init method.

272
00:13:03,000 --> 00:13:06,000
And here let me just go ahead and write self comma name.

273
00:13:06,000 --> 00:13:09,000
Name is what I'm going to pass as an attribute.

274
00:13:09,000 --> 00:13:13,000
And I will go ahead and create my attribute self dot name is equal to name right.

275
00:13:13,000 --> 00:13:16,000
So this becomes my animal class okay.

276
00:13:16,000 --> 00:13:17,000
And animal class.

277
00:13:17,000 --> 00:13:21,000
Let me just go ahead and create one function which is will be like speak okay.

278
00:13:21,000 --> 00:13:23,000
And here I'm going to use self.

279
00:13:24,000 --> 00:13:30,000
And let me just go ahead and uh, probably, um, uh, you know, print something.

280
00:13:30,000 --> 00:13:32,000
So here I will just go ahead and print.

281
00:13:34,000 --> 00:13:35,000
Okay.

282
00:13:36,000 --> 00:13:42,000
Sub classes must implement this method.

283
00:13:42,000 --> 00:13:44,000
Let's say I'm just going to write this.

284
00:13:46,000 --> 00:13:46,000
Okay.

285
00:13:46,000 --> 00:13:49,000
Now this is done with respect to my class.

286
00:13:49,000 --> 00:13:54,000
Right now, what I will do is that I will go ahead and create another base class.

287
00:13:54,000 --> 00:13:56,000
So this is one of my base class.

288
00:13:56,000 --> 00:13:59,000
So here I'll write base class one okay.

289
00:14:00,000 --> 00:14:01,000
Base class one.

290
00:14:01,000 --> 00:14:05,000
Because see what when a class inheritance inherits from more than one base class.

291
00:14:05,000 --> 00:14:07,000
So this is my base class one.

292
00:14:07,000 --> 00:14:10,000
Now let me just go ahead and create my base class two.

293
00:14:11,000 --> 00:14:14,000
So base class two okay.

294
00:14:14,000 --> 00:14:16,000
And here I'm just going to copy this.

295
00:14:16,000 --> 00:14:19,000
And here you can see I have this pet class.

296
00:14:19,000 --> 00:14:22,000
And I'm creating this init method with self comma owner.

297
00:14:22,000 --> 00:14:24,000
And I'm saying hey self dot owner is equal to owner okay.

298
00:14:25,000 --> 00:14:27,000
Now let's go ahead and create my derived class.

299
00:14:27,000 --> 00:14:31,000
Now derived class will be something like inheriting both these classes.

300
00:14:31,000 --> 00:14:37,000
Now in order to offer a child class to inherit both this class, I will go ahead and create class dog.

301
00:14:37,000 --> 00:14:37,000
Okay.

302
00:14:37,000 --> 00:14:43,000
And this time, in order to inherit both the classes, I will go ahead and write animal, comma, pet.

303
00:14:43,000 --> 00:14:48,000
Okay, so this is how you basically give in comma separated inside this brackets.

304
00:14:48,000 --> 00:14:54,000
Then what I will do from animal I will be taking this name class name attribute.

305
00:14:54,000 --> 00:14:57,000
I will be accessing this peak along with this from pet.

306
00:14:57,000 --> 00:14:59,000
I will be getting owner right.

307
00:14:59,000 --> 00:15:00,000
So here.

308
00:15:00,000 --> 00:15:06,000
If I want to use this owner attribute and name all I have to basically go ahead and right.

309
00:15:06,000 --> 00:15:09,000
I'll go ahead and create my init method okay.

310
00:15:09,000 --> 00:15:13,000
And here I'm going to give self comma name comma owner.

311
00:15:13,000 --> 00:15:14,000
Right.

312
00:15:14,000 --> 00:15:20,000
And here let me just go ahead and write animal dot underscore underscore init okay.

313
00:15:20,000 --> 00:15:24,000
So this is also another way of probably calling it right.

314
00:15:24,000 --> 00:15:28,000
Let's say I want to get the attribute of name from animal.

315
00:15:28,000 --> 00:15:29,000
Right.

316
00:15:29,000 --> 00:15:31,000
So this name is basically present in animal.

317
00:15:31,000 --> 00:15:36,000
So instead of just writing super Dot I can just write the class name dot in it.

318
00:15:36,000 --> 00:15:39,000
And here I can actually give self comma name.

319
00:15:39,000 --> 00:15:40,000
Okay.

320
00:15:40,000 --> 00:15:45,000
So this is one way uh the other way is that again I will go ahead and do it for the other class pet

321
00:15:45,000 --> 00:15:46,000
underscore init.

322
00:15:46,000 --> 00:15:48,000
Underscore underscore.

323
00:15:48,000 --> 00:15:53,000
And here also I'll go ahead and write self comma owner okay.

324
00:15:53,000 --> 00:15:55,000
Self comma owner.

325
00:15:55,000 --> 00:16:00,000
See what is the difference between before the methods that I have discussed here I have used super because

326
00:16:00,000 --> 00:16:02,000
I just had one parent class.

327
00:16:02,000 --> 00:16:06,000
But since here I have two parent class like base class one and base class two, right?

328
00:16:06,000 --> 00:16:12,000
I need to use one attribute from this particular attribute itself from this particular class animal,

329
00:16:12,000 --> 00:16:14,000
and one more from this, another base class.

330
00:16:14,000 --> 00:16:17,000
So what I'm doing I'm just writing animal dot underscore underscore init.

331
00:16:17,000 --> 00:16:19,000
I'm calling the animal init method.

332
00:16:19,000 --> 00:16:22,000
And then I'm passing this particular parameter.

333
00:16:22,000 --> 00:16:25,000
And then I'm calling pet underscore underscore init.

334
00:16:25,000 --> 00:16:27,000
And then I'm passing the parameter over there.

335
00:16:27,000 --> 00:16:32,000
And when it goes to this init method then this attribute gets the value of this right.

336
00:16:32,000 --> 00:16:34,000
This is how the entire flow goes.

337
00:16:34,000 --> 00:16:38,000
Now finally, let me just go ahead and create a speak method.

338
00:16:38,000 --> 00:16:41,000
So I'll just go ahead and write a definition speak.

339
00:16:41,000 --> 00:16:43,000
And here I'll go and say it is a self.

340
00:16:44,000 --> 00:16:46,000
Now let me just go ahead and return.

341
00:16:46,000 --> 00:16:48,000
So return will be an F string.

342
00:16:48,000 --> 00:16:58,000
And let's say here I'm going to basically write self dot name says HUF okay self dot name says HUF okay.

343
00:16:58,000 --> 00:16:58,000
Okay.

344
00:16:58,000 --> 00:17:00,000
And this is what is basically getting printed.

345
00:17:00,000 --> 00:17:02,000
So let me just go ahead and write a return over here.

346
00:17:03,000 --> 00:17:03,000
Okay.

347
00:17:03,000 --> 00:17:04,000
Now it should be working fine.

348
00:17:05,000 --> 00:17:07,000
Now let's see this how this will work.

349
00:17:07,000 --> 00:17:09,000
Now we'll go ahead and create an object.

350
00:17:09,000 --> 00:17:10,000
Okay.

351
00:17:10,000 --> 00:17:13,000
Create an object just to see that whether it is working fine or not.

352
00:17:13,000 --> 00:17:19,000
So here first of all I'll go ahead and call dog is equal to I will initialize from dog.

353
00:17:19,000 --> 00:17:22,000
Here I'm just going to write the name will be buddy.

354
00:17:23,000 --> 00:17:26,000
and the owner belongs to crush.

355
00:17:26,000 --> 00:17:32,000
Okay, let's say then I will go ahead and print dog Dot speak.

356
00:17:32,000 --> 00:17:37,000
And if I go ahead and execute this, you'll be able to see that I'll be getting buddy says woof.

357
00:17:37,000 --> 00:17:43,000
See, there is also a speak method over here, but since we are directly calling it from the dog class,

358
00:17:43,000 --> 00:17:47,000
so this will this speak method will be given more priority when compared to the parent class.

359
00:17:47,000 --> 00:17:48,000
Right.

360
00:17:48,000 --> 00:17:56,000
So that is the reason it is saying but he says woof okay, then I will just go ahead and print my F

361
00:17:56,000 --> 00:18:00,000
owner owner will be nothing but it will be self.

362
00:18:00,000 --> 00:18:13,000
Dot oh sorry dog dot owner right dog oh sorry dog dog dog dog dot owner Okay, so let me just go ahead

363
00:18:13,000 --> 00:18:14,000
and execute it.

364
00:18:14,000 --> 00:18:17,000
So here you'll be able to see that owner is nothing but crush.

365
00:18:17,000 --> 00:18:18,000
And buddy says woof.

366
00:18:18,000 --> 00:18:24,000
So here what we are doing here we are creating two parent class two separate base class okay.

367
00:18:24,000 --> 00:18:26,000
And we are inheriting them from a derived class.

368
00:18:26,000 --> 00:18:30,000
And this is basically called as multiple inheritance.

369
00:18:30,000 --> 00:18:30,000
Okay.

370
00:18:30,000 --> 00:18:32,000
Or we can also say it as multiple inheritance.

371
00:18:32,000 --> 00:18:32,000
Yes.

372
00:18:33,000 --> 00:18:35,000
Now, uh, let's do one thing.

373
00:18:35,000 --> 00:18:39,000
Uh, let's create an amazing use case.

374
00:18:39,000 --> 00:18:47,000
Uh, and, uh, this use case will be about modeling a complete library system, uh, that will discuss

375
00:18:47,000 --> 00:18:51,000
in our next video, uh, where we'll be modeling a complete library system.

376
00:18:51,000 --> 00:18:54,000
Here we there will be using single and multiple inheritance.

377
00:18:54,000 --> 00:18:56,000
So, yes, this was it for my side.

378
00:18:56,000 --> 00:18:57,000
I hope you liked this particular video.

379
00:18:58,000 --> 00:18:59,000
Uh, I will see you all in the next video.

380
00:18:59,000 --> 00:19:00,000
Thank you.

381
00:19:00,000 --> 00:19:00,000
Take care.

