1
00:00:02,170 --> 00:00:02,890
Hello everyone.

2
00:00:02,890 --> 00:00:06,030
So in this video I want to discuss about inheritance.

3
00:00:06,380 --> 00:00:06,690
OK.

4
00:00:06,730 --> 00:00:09,040
So what is the meaning of inheritance.

5
00:00:09,130 --> 00:00:14,210
So inheritance means to inherit some properties from our parents or ancestors.

6
00:00:14,260 --> 00:00:14,710
OK.

7
00:00:14,800 --> 00:00:20,440
So just like we humans do what we do we all inherit some correct districts from our parents or grandparents

8
00:00:20,740 --> 00:00:23,100
and some properties or qualities are our own.

9
00:00:23,590 --> 00:00:25,320
OK so let's say in code.

10
00:00:25,420 --> 00:00:27,160
So suppose I have three classes

11
00:00:30,740 --> 00:00:34,820
bicycle and I have a class truck.

12
00:00:34,990 --> 00:00:35,570
Okay.

13
00:00:35,600 --> 00:00:44,870
So the properties of car class are color color of the car maximum speed of the car and let's say the

14
00:00:44,870 --> 00:00:46,640
number of gears.

15
00:00:46,640 --> 00:00:46,900
Okay.

16
00:00:46,940 --> 00:00:55,160
So number of gears and louder let's talk about the properties of bicycle to color of the bicycle max

17
00:00:55,160 --> 00:01:00,030
speed and obviously bicycle doesn't have gears.

18
00:01:00,030 --> 00:01:02,670
So let's say we have a billion property is for level.

19
00:01:02,690 --> 00:01:04,530
So some bicycle s for level.

20
00:01:04,620 --> 00:01:06,110
So we have a property billion.

21
00:01:06,150 --> 00:01:08,060
Property is for level.

22
00:01:08,100 --> 00:01:08,590
Okay.

23
00:01:08,670 --> 00:01:10,600
Now let us talk about truck.

24
00:01:10,620 --> 00:01:21,330
So conserve the truck max speed of their truck and some other drug related properties okay.

25
00:01:21,470 --> 00:01:25,640
So what is happening here is some properties are common in many classes.

26
00:01:25,640 --> 00:01:25,950
Okay.

27
00:01:25,980 --> 00:01:30,850
So common common and common.

28
00:01:31,470 --> 00:01:31,880
Okay.

29
00:01:31,930 --> 00:01:37,090
So these properties and some properties are common in many classes because they all have one feature

30
00:01:37,090 --> 00:01:40,390
in common all three belongs to vehicle.

31
00:01:40,390 --> 00:01:40,680
Okay.

32
00:01:40,690 --> 00:01:42,400
All three are vehicle.

33
00:01:42,460 --> 00:01:48,980
So what is happening here is so I have a class vehicle.

34
00:01:49,330 --> 00:01:59,090
So all the three things car bicycle and truck they all have one feature in common.

35
00:01:59,110 --> 00:02:00,940
All three are vehicles.

36
00:02:01,030 --> 00:02:01,720
Okay.

37
00:02:01,780 --> 00:02:07,530
So now my aim is I have to create these three classes okay.

38
00:02:07,560 --> 00:02:09,660
So I have to create three classes

39
00:02:12,350 --> 00:02:13,670
guide bicycle and truck.

40
00:02:14,180 --> 00:02:17,840
So the first race just like we created these classes.

41
00:02:17,900 --> 00:02:21,680
So the first race we will create classes in this manner.

42
00:02:21,680 --> 00:02:25,640
First some common properties then candidate properties.

43
00:02:25,640 --> 00:02:29,810
Then again some common properties then bicycle related properties.

44
00:02:29,810 --> 00:02:33,990
Again some common properties and then regulated properties.

45
00:02:34,010 --> 00:02:34,550
Okay.

46
00:02:34,610 --> 00:02:40,150
Now the second way to create these three classes in a good way in a in an appropriate way.

47
00:02:40,350 --> 00:02:41,770
It is what we will do.

48
00:02:41,840 --> 00:02:50,810
We will move these properties inside difficult class okay so that we could class will have color and

49
00:02:50,810 --> 00:02:53,600
the vehicle will obviously have the max speed.

50
00:02:54,380 --> 00:02:54,650
Okay.

51
00:02:54,650 --> 00:02:55,940
And we will remove it from here.

52
00:02:56,390 --> 00:02:56,650
Okay.

53
00:02:56,660 --> 00:02:59,630
So remove these things from the bicycle class.

54
00:02:59,660 --> 00:03:05,150
Remove the common properties from the track class okay.

55
00:03:05,180 --> 00:03:06,000
So we have to move.

56
00:03:06,000 --> 00:03:07,880
Common properties to difficult class.

57
00:03:07,890 --> 00:03:15,990
So vehicle is our parent vehicle is our parent class and car is a child.

58
00:03:16,080 --> 00:03:23,500
Child class bicycle is a child class truck is a child a class okay.

59
00:03:23,540 --> 00:03:30,500
So what really happened that car class will have some kind of specific properties and the common properties

60
00:03:30,560 --> 00:03:33,230
it will inherit from its parent.

61
00:03:33,830 --> 00:03:34,150
Okay.

62
00:03:34,180 --> 00:03:40,100
Similarly bicycle will have some properties of its own bicycle later properties and other properties

63
00:03:40,220 --> 00:03:42,030
it will inherit from vehicle.

64
00:03:42,200 --> 00:03:47,840
Similarly truck will have some percolated properties truck specific properties and the common properties

65
00:03:48,080 --> 00:03:52,110
it will inherit from its parent that is difficult class.

66
00:03:52,160 --> 00:03:52,570
Okay.

67
00:03:52,640 --> 00:03:55,600
Now suppose I want to create one more class here.

68
00:03:55,760 --> 00:03:57,500
Okay so I want to create one more class.

69
00:03:57,500 --> 00:04:04,460
Let's say the name of the class is bike so the name of the classes bike.

70
00:04:04,510 --> 00:04:05,950
Now what bike will do.

71
00:04:06,130 --> 00:04:13,840
It will inherit some common properties it will inherit color and the max speed from the vehicle class

72
00:04:14,230 --> 00:04:18,140
and some properties will be related to the bike specific properties.

73
00:04:18,730 --> 00:04:23,570
Okay so the second way is the most appropriate way to create classes.

74
00:04:23,620 --> 00:04:25,010
Okay so whatever approach.

75
00:04:25,140 --> 00:04:25,480
Move.

76
00:04:25,480 --> 00:04:33,730
Common properties to a common class to one class create one class which is the parent of all the classes

77
00:04:34,030 --> 00:04:36,370
and move the common properties there.

78
00:04:36,370 --> 00:04:36,730
Okay.

79
00:04:37,890 --> 00:04:41,990
So let us take one more example to understand it better.

80
00:04:43,570 --> 00:04:53,210
OK so suppose I ever teach a class and I have a student class teacher class end student class.

81
00:04:53,230 --> 00:04:55,990
So now let us talk about some properties of the teacher.

82
00:04:56,170 --> 00:05:01,360
So teacher will have a name age of the teacher will be a property.

83
00:05:01,420 --> 00:05:03,970
Similarly address contact number

84
00:05:07,750 --> 00:05:16,750
and let's say qualifications without the qualification of their teacher expertise area.

85
00:05:16,890 --> 00:05:19,150
So these are some properties of a teacher.

86
00:05:19,170 --> 00:05:21,660
Now let us talk about the properties of the student.

87
00:05:21,660 --> 00:05:29,130
So a student will have a name and will have age similarly address contact number

88
00:05:32,240 --> 00:05:33,140
a student will have.

89
00:05:33,140 --> 00:05:40,220
Rule number badge number and so on.

90
00:05:40,290 --> 00:05:49,870
Okay so now we can see here again some properties are common name age address contact number and here

91
00:05:49,900 --> 00:05:53,570
also some properties are common.

92
00:05:53,830 --> 00:05:57,370
Okay so now what we will do we have learned about inheritance.

93
00:05:57,370 --> 00:05:58,740
We will create a new class.

94
00:05:58,750 --> 00:06:06,020
We will create one class let's say the name of this class is human class.

95
00:06:06,290 --> 00:06:12,520
We will move the common properties here and we will remove the common properties from here okay.

96
00:06:12,530 --> 00:06:17,280
So remove the common properties because the common properties will now belong to human class.

97
00:06:17,380 --> 00:06:21,410
So all human will have name it will have each.

98
00:06:21,770 --> 00:06:24,920
It will have address and it will have contact number

99
00:06:28,830 --> 00:06:29,020
so.

100
00:06:29,040 --> 00:06:32,860
Teacher class will contain only teacher specific properties.

101
00:06:32,860 --> 00:06:38,210
Student class will contain only student specific properties and all the other properties.

102
00:06:38,230 --> 00:06:38,950
What it will do.

103
00:06:38,980 --> 00:06:41,280
It will inherit from its parent.

104
00:06:42,190 --> 00:06:46,600
Okay so we will inherit the common properties from our parents.

105
00:06:46,600 --> 00:06:52,090
Again we will inherit some properties from our parents and some properties will be our own.

106
00:06:52,900 --> 00:07:02,550
Okay so we are inheriting common properties Okay so human is our patent class human is our parent and

107
00:07:02,700 --> 00:07:04,320
teacher and student.

108
00:07:04,380 --> 00:07:05,670
They both had a child.

109
00:07:05,680 --> 00:07:08,420
Child classes okay.

110
00:07:08,570 --> 00:07:10,310
So what is the main purpose.

111
00:07:10,310 --> 00:07:13,290
What is the main benefit of using inheritance.

112
00:07:14,780 --> 00:07:19,430
So the main benefit of using inheritance is reusing the called

113
00:07:23,380 --> 00:07:25,150
We are reusing the code.

114
00:07:25,150 --> 00:07:32,820
Okay so move all the common things at one place and whenever that common thing is acquired just inherited

115
00:07:32,850 --> 00:07:34,050
the common properties.

116
00:07:34,050 --> 00:07:38,820
Okay so this is the main benefit of using inheritance reusing the gold.

117
00:07:38,820 --> 00:07:39,100
Okay.

118
00:07:39,120 --> 00:07:45,780
We will just write the code once and if someone wants those properties just inherit the properties.

119
00:07:45,810 --> 00:07:46,070
Okay.

120
00:07:46,110 --> 00:07:49,920
So the main benefit of inheritances reusing the code

121
00:07:52,860 --> 00:07:53,350
okay.

122
00:07:53,420 --> 00:07:57,730
Now let's talk about excess modifiers.

123
00:07:57,780 --> 00:08:00,150
Now let's talk about excess modifiers

124
00:08:03,560 --> 00:08:08,820
so we already know about to excess modifiers public and private.

125
00:08:09,140 --> 00:08:16,100
So we have already started about private and we have already started about public so private means it

126
00:08:16,100 --> 00:08:22,460
is not accessible outside the class and public means it is accessible to anyone outside the class.

127
00:08:22,460 --> 00:08:25,130
Okay so they both are very extreme.

128
00:08:25,130 --> 00:08:29,420
Private is very strong and public is very lenient okay.

129
00:08:29,420 --> 00:08:37,550
So we want something in between and there is something in between the public and private is called protected.

130
00:08:37,670 --> 00:08:38,140
Okay.

131
00:08:38,240 --> 00:08:39,800
So what is protected.

132
00:08:39,800 --> 00:08:40,570
So what will happen.

133
00:08:40,580 --> 00:08:47,700
Let's say I have a class and inside the class if I declare a property X to be a protected property.

134
00:08:47,730 --> 00:08:48,830
So what will happen.

135
00:08:48,870 --> 00:08:56,790
So this protected property is accessible to someone outside the class and is not accessible to the others.

136
00:08:56,880 --> 00:08:57,550
Okay.

137
00:08:57,720 --> 00:09:04,620
So if I declare a property X a protected property for this protected property will be accessible outside

138
00:09:04,620 --> 00:09:11,150
the class for only for some people and for that it will not be accessible okay.

139
00:09:11,310 --> 00:09:18,210
So X is a property I've owned the property that would be accessible for some person and not accessible

140
00:09:18,240 --> 00:09:19,320
for the rest of the world.

141
00:09:19,560 --> 00:09:22,280
So we will declare that property as a protected property.

142
00:09:22,590 --> 00:09:31,020
Okay so let's say I have two classes Class A and Class B Class A is a parent class and class B is a

143
00:09:31,020 --> 00:09:33,300
child's class.

144
00:09:33,780 --> 00:09:34,070
Okay.

145
00:09:34,080 --> 00:09:36,490
So B inherit some property from me.

146
00:09:36,510 --> 00:09:38,860
Okay so let us take the call in God.

147
00:09:39,090 --> 00:09:40,890
So I have vehicle and God.

148
00:09:40,920 --> 00:09:42,030
So God is a child.

149
00:09:42,030 --> 00:09:44,760
Class and vehicle is a parent.

150
00:09:44,760 --> 00:09:51,620
Class Okay so God will inherit some of its properties from the vehicle class.

151
00:09:51,750 --> 00:09:58,170
Okay so what will happen if a property is protected then it is only accessible to child class.

152
00:09:58,380 --> 00:09:59,970
So let us take an example.

153
00:10:03,220 --> 00:10:07,270
So suppose this is working class and inside the working class.

154
00:10:07,480 --> 00:10:10,770
I have declared a property X as a protected property.

155
00:10:10,900 --> 00:10:11,680
So what will happen.

156
00:10:11,700 --> 00:10:19,200
So this protected property X is accessible outside the class but only for those classes which inherit

157
00:10:19,230 --> 00:10:20,820
from the vehicle class.

158
00:10:20,820 --> 00:10:28,710
Okay so this protected property X is accessible outside the class but only for those classes which inherit

159
00:10:28,800 --> 00:10:29,910
from vehicle class.

160
00:10:29,970 --> 00:10:33,450
That is only the child classes of the class.

161
00:10:33,870 --> 00:10:35,940
Okay so what I am saying is.

162
00:10:36,150 --> 00:10:44,790
So what I am saying here is let's say I have a vehicle class so I have a class vehicle inside the vehicle.

163
00:10:44,800 --> 00:10:54,700
I have a public property X Y and Z so access public values private and Z is protected

164
00:10:58,400 --> 00:11:00,800
and this is outside.

165
00:11:01,430 --> 00:11:07,710
Okay so public property X anyone can access public property X outside the class.

166
00:11:07,940 --> 00:11:08,340
Okay.

167
00:11:08,420 --> 00:11:10,840
X is accessible for everyone okay.

168
00:11:10,880 --> 00:11:18,950
Anyone can access anyone can access X because X is a public property outside the class private property

169
00:11:18,950 --> 00:11:27,050
y no one can access the private property why outside the class protected properties and it is accessible

170
00:11:27,110 --> 00:11:36,200
outside the class but using only roads child classes using only its child classes

171
00:11:39,760 --> 00:11:40,160
okay.

172
00:11:40,290 --> 00:11:47,040
So public property X anyone can access outside the class no one can access outside the class it is accessible

173
00:11:47,040 --> 00:11:48,850
outside the class but using only it.

174
00:11:48,860 --> 00:11:58,960
Child classes Okay so suppose this is our vehicle class and there are three other classes which I inherited

175
00:11:58,960 --> 00:12:03,500
from the working class and these are car is a child class of vehicle.

176
00:12:03,670 --> 00:12:08,960
Bicycle is also the child class of vehicle and truck is also the child the class of vehicle.

177
00:12:08,980 --> 00:12:17,880
Similarly let's say I have a class human so a human teacher and student inherits from human.

178
00:12:18,100 --> 00:12:28,920
Okay now let's talk about protected properties and okay so obviously vehicle can access the protected

179
00:12:28,920 --> 00:12:32,650
properties and God can access the protected property.

180
00:12:32,670 --> 00:12:38,570
Bicycle can access that and truck can access it and why because the oil out of child classes or difficult

181
00:12:38,600 --> 00:12:45,540
class so human cannot access that teacher cannot access it and student cannot access it.

182
00:12:45,720 --> 00:12:52,490
Okay so this is human cannot access student cannot access and teacher cannot access the protected property.

183
00:12:52,530 --> 00:12:54,890
Z of the class.

184
00:12:54,900 --> 00:13:00,720
Okay so if you want to access the protected property there should be a relation between the parent class

185
00:13:00,720 --> 00:13:01,770
and the child class.

186
00:13:01,800 --> 00:13:02,730
Okay.

187
00:13:03,160 --> 00:13:10,110
So I hope you know what is protected now so protected properties only accessible using.

188
00:13:10,110 --> 00:13:17,760
Child classes okay since human does not have any relation with the vehicle so it cannot access Z if

189
00:13:17,760 --> 00:13:23,580
human cannot exist then obviously teacher and student those who cannot access okay.

190
00:13:23,910 --> 00:13:24,330
Thank you.
