1
00:00:01,710 --> 00:00:02,400
Hello everyone.

2
00:00:02,400 --> 00:00:07,980
So in the last week we discussed how construct a sound destruct those are calling gifts of inheritance.

3
00:00:07,980 --> 00:00:11,360
So in this we do I want to discuss different types of inheritance.

4
00:00:11,400 --> 00:00:19,620
Okay so the first one is Single inheritance.

5
00:00:19,630 --> 00:00:21,840
Now what is the meaning of Single inheritance.

6
00:00:21,850 --> 00:00:25,060
So it means only one parent and one child.

7
00:00:25,060 --> 00:00:28,480
Okay so class be inherited glasses.

8
00:00:28,510 --> 00:00:35,110
So one parent and one child vehicle and God.

9
00:00:35,190 --> 00:00:37,770
Okay so only one parent and one child.

10
00:00:37,770 --> 00:00:40,740
So what is this index syntax is quite familiar.

11
00:00:40,810 --> 00:00:46,760
Class God then access modify it and then the name of the class which is we call.

12
00:00:46,990 --> 00:00:50,680
Okay so this is the syntax for Single inheritance.

13
00:00:50,720 --> 00:00:54,580
Now the second is we have multi level

14
00:00:57,200 --> 00:00:58,560
multi level inheritance

15
00:01:01,220 --> 00:01:01,480
okay.

16
00:01:01,490 --> 00:01:04,050
So what is the meaning of multi-level inheritance.

17
00:01:04,070 --> 00:01:08,010
So in multilevel inheritance we have multiple levels.

18
00:01:08,030 --> 00:01:08,630
Okay.

19
00:01:08,630 --> 00:01:16,220
So for example Class B inherited from Glass a glossy inherits from Class B and so on.

20
00:01:16,220 --> 00:01:16,780
Okay.

21
00:01:16,820 --> 00:01:23,210
So we took an example in the last session so we could class this guide class inherits from the working

22
00:01:23,210 --> 00:01:28,490
class and then we have 130 class which inherits from the Carter class.

23
00:01:28,490 --> 00:01:35,430
Okay so how do the properties will be accessible so well it depends upon the access modifiers you use.

24
00:01:35,450 --> 00:01:36,330
Okay.

25
00:01:36,440 --> 00:01:44,730
Now the third one is now the third one is hierarchal inheritance.

26
00:01:44,770 --> 00:01:47,740
Okay so radical.

27
00:01:47,750 --> 00:01:52,790
Inheritance so what is the meaning of identical inheritance.

28
00:01:52,800 --> 00:01:56,790
So in this case we have one parent and multiple child.

29
00:01:56,790 --> 00:02:04,460
Okay so only one parent will be there and there will be multiple child B C and D.

30
00:02:04,530 --> 00:02:06,360
Okay now let us take an example.

31
00:02:06,360 --> 00:02:14,570
So we have a weaker class car class inherits from the class bicycle class inherited from the working

32
00:02:14,640 --> 00:02:15,320
class.

33
00:02:15,390 --> 00:02:18,130
And similarly that class will inherit from the.

34
00:02:18,150 --> 00:02:19,070
We could class.

35
00:02:19,140 --> 00:02:22,880
Okay so multiple class in added the base class.

36
00:02:22,950 --> 00:02:24,370
So what is this index.

37
00:02:24,420 --> 00:02:33,540
So this index is quite familiar for example if we want to use track class so class truck and then public

38
00:02:34,670 --> 00:02:37,650
vehicle public is the access modifier.

39
00:02:38,000 --> 00:02:41,900
Okay so let's say in gold although the code is not necessary but let's see

40
00:02:44,670 --> 00:02:49,490
so I want to create a class class drug.

41
00:02:49,740 --> 00:02:55,200
Now this class drug inheritance tax is modified is public and it inherits from the working class.

42
00:02:55,240 --> 00:02:55,500
Okay

43
00:02:58,750 --> 00:03:00,670
and that's all okay.

44
00:03:01,010 --> 00:03:06,640
So we can see here is Class Card which also notes from the working class.

45
00:03:06,710 --> 00:03:11,380
And similarly there is a class drug which also includes some division of class.

46
00:03:11,390 --> 00:03:11,660
Okay

47
00:03:14,690 --> 00:03:18,050
so this was hierarchal inheritance.

48
00:03:18,740 --> 00:03:21,740
Okay now let's see the next one.

49
00:03:21,740 --> 00:03:30,690
So the next one is the fourth one is now this is a multi-level might be level inheritance

50
00:03:33,210 --> 00:03:40,800
so what happened in multi-level inheritances so one class will inherit from multiple base classes.

51
00:03:40,840 --> 00:03:41,540
Okay.

52
00:03:41,560 --> 00:03:51,100
One class will inherit from multiple base class letters a b c and d a Class D so one class will inherit

53
00:03:51,250 --> 00:03:54,080
from the multiple base classes.

54
00:03:54,110 --> 00:03:59,900
Okay so suppose we have Teacher Teacher class and student class

55
00:04:02,650 --> 00:04:05,630
and the third one is the teaching assistant.

56
00:04:05,630 --> 00:04:12,310
Okay so a teaching assistant will have some properties of teacher and teaching assistant is also a student.

57
00:04:12,310 --> 00:04:17,330
Okay so when a class will inherit from the multiple B's classes.

58
00:04:17,440 --> 00:04:18,610
Okay so let's say in good

59
00:04:22,250 --> 00:04:28,920
so I have this class multiple inheritance starts CPB sorry I have this file multiple in our TPP Let's

60
00:04:28,940 --> 00:04:30,320
create two classes.

61
00:04:30,530 --> 00:04:40,540
So class teacher so this class teacher has some public properties let's say the properties are name

62
00:04:40,660 --> 00:04:41,710
and age.

63
00:04:41,740 --> 00:04:52,910
Okay so String name and legacy and Deej also let's say there is a print function where the print inside

64
00:04:52,910 --> 00:04:55,370
the brain function let's print something.

65
00:04:55,460 --> 00:04:56,570
Okay so we'll see old

66
00:04:59,490 --> 00:05:05,350
digit Okay now let us also create a class.

67
00:05:05,410 --> 00:05:08,800
Student So we have a class.

68
00:05:08,800 --> 00:05:11,050
Student now this student.

69
00:05:11,050 --> 00:05:16,930
Class let's say it also has a function print.

70
00:05:16,920 --> 00:05:17,900
So void print.

71
00:05:24,590 --> 00:05:28,420
And now that this print a student inside the print function.

72
00:05:28,520 --> 00:05:39,100
So student Okay now we have a class teaching assistant so this class teaching assistant as you can see

73
00:05:39,100 --> 00:05:45,880
here this class teaching assistant it inherited from both the classes or damage it inherited from the

74
00:05:45,880 --> 00:05:48,040
teacher as well as from the student class.

75
00:05:48,220 --> 00:05:48,860
Okay.

76
00:05:49,000 --> 00:05:56,350
And let's see the excess specified is public so class teaching assistant this index is very similar.

77
00:05:56,350 --> 00:05:58,970
First we have to rate the excess modifier.

78
00:05:59,080 --> 00:06:08,200
Let's say the excess modifier for the teacher class is public then coma again excess specified for the

79
00:06:08,200 --> 00:06:09,060
student class.

80
00:06:09,190 --> 00:06:11,320
And then the name of the student class.

81
00:06:11,320 --> 00:06:17,670
Okay so this is this index for multiple inheritance.

82
00:06:17,680 --> 00:06:24,570
Okay so this class teaching assistant it inherits from both teacher class and grade class.

83
00:06:24,730 --> 00:06:27,790
And for both the access specified is public.

84
00:06:27,820 --> 00:06:28,680
Okay.

85
00:06:28,840 --> 00:06:35,520
Now what will happen if I want to create an object of their teaching assistant so teaching assistant.

86
00:06:35,530 --> 00:06:39,370
Let's see the object is a the name of the object is it.

87
00:06:39,850 --> 00:06:44,020
So what is happening here is okay.

88
00:06:44,040 --> 00:06:46,560
So we have teacher and student.

89
00:06:46,560 --> 00:06:55,150
So I have a class teacher and I have a class student and then I have a class teaching assistant it inherits

90
00:06:55,230 --> 00:06:56,910
from the teacher and the student.

91
00:06:57,120 --> 00:06:57,630
So

92
00:07:00,430 --> 00:07:09,430
this is teaching assistant class and teaching assistant class in edits from teacher as well as it inherits

93
00:07:09,520 --> 00:07:10,840
from the student.

94
00:07:11,980 --> 00:07:18,970
Okay now what will happen when I write this statement when I'm creating the object of the teaching assistant

95
00:07:18,970 --> 00:07:22,480
class then whose construct that will be called first.

96
00:07:22,840 --> 00:07:27,790
Okay so it generates from teacher and it then added strums truant from what the classes.

97
00:07:28,030 --> 00:07:32,450
So whose construct will be called first teacher or student.

98
00:07:32,470 --> 00:07:37,790
Okay so the answer is teacher y teacher because I write teacher first.

99
00:07:37,870 --> 00:07:41,620
Okay so because I write the name of the teacher class first.

100
00:07:41,620 --> 00:07:42,280
So that's why.

101
00:07:42,550 --> 00:07:46,840
First of all teacher constructor will be called then student constructively record.

102
00:07:46,840 --> 00:07:51,820
And finally the teaching assistant constructor will be called when we are creating the object of the

103
00:07:51,820 --> 00:07:52,570
teaching assistant.

104
00:07:52,600 --> 00:07:55,180
Class okay.

105
00:07:55,630 --> 00:07:59,220
Now let us try to not let us use the print function.

106
00:07:59,240 --> 00:08:04,790
Okay so now let's call the print function.

107
00:08:04,810 --> 00:08:07,450
So what will happen.

108
00:08:07,630 --> 00:08:07,930
Okay.

109
00:08:07,960 --> 00:08:10,410
So if I run this file there will be an error.

110
00:08:10,420 --> 00:08:12,640
Now let us try to understand why the error will come

111
00:08:15,750 --> 00:08:17,790
so what is happening it is.

112
00:08:17,790 --> 00:08:23,370
So first of all this print function is accessible for teaching assistant.

113
00:08:23,370 --> 00:08:23,960
Why.

114
00:08:24,000 --> 00:08:27,210
Because as you can see here is print function is public.

115
00:08:27,240 --> 00:08:32,070
And similarly the print function is public here and we are using the access specified public.

116
00:08:32,130 --> 00:08:34,770
So teaching assistant has access to the print function.

117
00:08:34,800 --> 00:08:43,020
Okay now what is happening here is we have a teaching assistant class and in their teaching assistant

118
00:08:43,030 --> 00:08:51,880
class we have a teacher and we have a student and teacher class has a brain function.

119
00:08:51,880 --> 00:08:55,530
Similarly student class also has a print function.

120
00:08:55,600 --> 00:09:02,050
So when I am calling the print function I am telling you there will be an error and that I will be there

121
00:09:02,080 --> 00:09:07,550
because there is ambiguity whose print function to call compiler will get confused.

122
00:09:07,570 --> 00:09:13,800
Okay so compiler will get confused among whose print function to call Deja brain function or Australian

123
00:09:13,810 --> 00:09:15,050
print function.

124
00:09:15,070 --> 00:09:17,790
Okay so that's why I edit will be there.

125
00:09:17,830 --> 00:09:22,120
If the print function is present in one class then there will be no idea.

126
00:09:22,240 --> 00:09:27,610
Okay so suppose if the print function was not present here then obviously there will be no error obviously.

127
00:09:27,640 --> 00:09:29,680
Then this print function would have been called.

128
00:09:29,770 --> 00:09:33,640
Okay but what is happening it is both the teacher and the student classes.

129
00:09:33,640 --> 00:09:37,070
They both have the print function exactly the same name.

130
00:09:37,120 --> 00:09:42,970
That's why the compiler will get confused because there is ambiguity whose print function to call.

131
00:09:43,250 --> 00:09:43,530
Okay.

132
00:09:43,570 --> 00:09:48,610
So if we will run this file we will get an error and that it will be saying like like there is some

133
00:09:48,610 --> 00:09:50,730
ambiguity in the brain function.

134
00:09:50,740 --> 00:09:53,850
Okay so let's try to this file.

135
00:09:53,920 --> 00:09:54,220
Okay.

136
00:09:57,950 --> 00:10:04,190
So we are getting an error at this line and that will be something like print function present in multiple

137
00:10:04,190 --> 00:10:05,030
base classes.

138
00:10:05,030 --> 00:10:06,620
Okay so we have two basic classes.

139
00:10:06,650 --> 00:10:08,960
Student and teacher.

140
00:10:08,960 --> 00:10:13,550
So we have two base classes and the brain function is present in multiple base classes something like

141
00:10:13,550 --> 00:10:14,030
this.

142
00:10:14,030 --> 00:10:14,960
Okay.

143
00:10:15,140 --> 00:10:20,960
Now how can we resolve this issue so to resolve this that we have to specify the class name.

144
00:10:20,960 --> 00:10:25,760
Okay suppose I want to call the print function present in this to rent class.

145
00:10:25,940 --> 00:10:33,380
So what I will write a dot student name of the class whose print function we have to call and the scope

146
00:10:33,380 --> 00:10:34,680
resolution operator.

147
00:10:34,800 --> 00:10:35,280
Okay.

148
00:10:35,330 --> 00:10:36,910
Now this time I will run this file.

149
00:10:36,920 --> 00:10:39,440
There will be no error and output will be student.

150
00:10:39,880 --> 00:10:40,520
Okay.

151
00:10:40,670 --> 00:10:43,900
This this print function will be called.

152
00:10:44,030 --> 00:10:46,330
Okay so this print function will be called.

153
00:10:46,370 --> 00:10:47,780
Okay let's straight on this file

154
00:10:51,110 --> 00:10:52,770
so a student is getting printed.

155
00:10:53,390 --> 00:10:53,650
Okay.

156
00:10:56,010 --> 00:11:01,370
Now what if this teaching assistant class also has the function brain function.

157
00:11:01,380 --> 00:11:08,130
Okay now what I'm telling you is now where did the teaching assistant class also has the function print

158
00:11:11,840 --> 00:11:13,280
and inside the brain function.

159
00:11:13,280 --> 00:11:16,150
I am writing teaching assistant Okay.

160
00:11:16,520 --> 00:11:23,910
Now what will happen and let's say if I run this file then the output will be student only because it

161
00:11:23,910 --> 00:11:27,780
is very clear here that we are not we want to call the brain function as truly in class.

162
00:11:27,820 --> 00:11:32,460
OK so let's send this file produced protested and no doubt.

163
00:11:32,540 --> 00:11:36,160
Now what if I remove the student.

164
00:11:36,550 --> 00:11:38,980
Now what will happen if I do a dot print.

165
00:11:39,130 --> 00:11:45,470
Will we get any added Now they're desperate to find out.

166
00:11:45,540 --> 00:11:56,370
So this is our teaching assistant class so in that teaching assistant class we have teacher and it inherited

167
00:11:56,400 --> 00:11:57,690
from a student.

168
00:11:57,810 --> 00:12:00,720
So teacher has a print function.

169
00:12:00,720 --> 00:12:07,410
Student also has a print function and teaching assistant has also has a print function.

170
00:12:07,410 --> 00:12:10,610
So what happens internally is when we write it out.

171
00:12:11,010 --> 00:12:16,830
So what it will do first of all we will search in the teaching assistant class and the teaching assistant

172
00:12:16,830 --> 00:12:19,050
class has a function called Print.

173
00:12:19,050 --> 00:12:22,040
Since the teaching of history in class has a function called print.

174
00:12:22,140 --> 00:12:25,080
So we will not go to its parent classes.

175
00:12:25,580 --> 00:12:32,370
Okay we will not go to its parent classes and this print function will be called and our output will

176
00:12:32,370 --> 00:12:34,380
be D.

177
00:12:34,560 --> 00:12:35,090
Okay.

178
00:12:35,160 --> 00:12:41,370
Now what happens is in the earlier case their teaching assistant class doesn't have a print function.

179
00:12:41,370 --> 00:12:46,320
So if the teaching assistant class doesn't have a brain function then we will go to it parent classes

180
00:12:46,620 --> 00:12:48,810
and both the parent classes as print function.

181
00:12:48,840 --> 00:12:52,030
That's why there will be an added ambiguity in it.

182
00:12:52,110 --> 00:12:53,690
Okay.

183
00:12:53,700 --> 00:12:59,310
So let's try to run this file and our output will be teaching assistant.

184
00:12:59,610 --> 00:13:06,240
Okay so our output is teaching assistant now just like the function if we have multiple data members

185
00:13:06,240 --> 00:13:12,240
with the same name then we will also get the error and that it will be like did the member present in

186
00:13:12,240 --> 00:13:19,290
multiple base classes for example this teacher the teacher class has a string name property let's say

187
00:13:22,140 --> 00:13:24,010
three and also has the name property.

188
00:13:24,010 --> 00:13:24,950
Okay.

189
00:13:25,360 --> 00:13:27,910
Now we can see here same name.

190
00:13:27,920 --> 00:13:29,180
Okay.

191
00:13:29,370 --> 00:13:34,480
Now if I want to let's say I want to access the name date remember.

192
00:13:34,530 --> 00:13:37,960
So a node name is let's say a b c d.

193
00:13:37,980 --> 00:13:42,470
Now if I had this file I will again get data and that it will be ambiguity added.

194
00:13:42,480 --> 00:13:43,550
Okay.

195
00:13:43,830 --> 00:13:45,370
So we are getting an added.

196
00:13:45,390 --> 00:13:46,850
Now how to resolve this error.

197
00:13:46,920 --> 00:13:49,890
Again we have to specify the last name.

198
00:13:49,890 --> 00:13:53,010
I want to exist the name property of the teacher class.

199
00:13:53,070 --> 00:13:56,110
So a dot teacher school resolution operator.

200
00:13:56,160 --> 00:13:56,650
Okay.

201
00:13:56,790 --> 00:13:59,260
Now let us on this file.

202
00:13:59,350 --> 00:14:01,320
So now all code is working fine.

203
00:14:01,330 --> 00:14:02,210
Okay.

204
00:14:02,710 --> 00:14:04,680
Now let us revise everything.

205
00:14:05,230 --> 00:14:10,960
So we have discussed four types of inheritance single multilevel and hierarchical all the three were

206
00:14:10,960 --> 00:14:11,620
very simple.

207
00:14:11,620 --> 00:14:16,630
The last one which was multiple this was a little bit tough.

208
00:14:16,630 --> 00:14:18,730
Now what happens in multiple is.

209
00:14:18,730 --> 00:14:25,900
Suppose you have three classes a b and c and let's say you have a class D and class D and added from

210
00:14:25,930 --> 00:14:30,970
all the classes glossy class B and classy.

211
00:14:31,000 --> 00:14:33,280
So this is the example of a multiple.

212
00:14:33,280 --> 00:14:35,450
It is the example of multiple inheritance.

213
00:14:35,500 --> 00:14:38,100
What is the problem with multiple inheritances.

214
00:14:38,140 --> 00:14:44,290
So if you ever need a member or function with the same name in multiple base classes then there will

215
00:14:44,290 --> 00:14:45,140
be an added.

216
00:14:45,340 --> 00:14:46,940
And how does all this error.

217
00:14:46,960 --> 00:14:54,700
So we have to specify the class name so d dot first of all that last name then the school resolution

218
00:14:54,700 --> 00:14:57,990
operator and then the property name.

219
00:14:58,200 --> 00:15:05,160
Okay so what is the problem with multiple inheritance if more than one if more than one base class.

220
00:15:05,180 --> 00:15:10,440
But as a written member with the same name or the function name then they will be added ambiguity it.

221
00:15:10,570 --> 00:15:11,230
Okay.

222
00:15:11,260 --> 00:15:12,200
And resolve this error.

223
00:15:12,220 --> 00:15:15,950
We have to specify the class name first and then the property name.

224
00:15:16,000 --> 00:15:16,600
Okay.

225
00:15:16,630 --> 00:15:19,900
And the second was if the properties also present.

226
00:15:19,900 --> 00:15:25,570
Suppose the properties also present in class D then that property will be accessed.

227
00:15:25,570 --> 00:15:25,870
Okay.

228
00:15:25,870 --> 00:15:27,380
Then there is no confusion.

229
00:15:27,460 --> 00:15:31,580
We can simply access this property okay.

230
00:15:31,630 --> 00:15:37,930
Now there is also a fifth type of inheritance which is the hybrid inheritance which we will discuss

231
00:15:38,020 --> 00:15:38,960
in the next video.

232
00:15:39,570 --> 00:15:40,180
Okay.

233
00:15:40,180 --> 00:15:40,600
Thank you.
