1
00:00:01,310 --> 00:00:02,030
Hello everyone.

2
00:00:02,030 --> 00:00:07,360
So in this video we will discuss some more concepts of object oriented programming.

3
00:00:07,400 --> 00:00:11,350
So in the last video we discussed about excess modifiers.

4
00:00:11,630 --> 00:00:16,780
We know how public and private affected the accessibility of the properties of the class.

5
00:00:16,820 --> 00:00:21,150
So we created this class in the last video.

6
00:00:21,170 --> 00:00:24,500
It has two properties rule number and age.

7
00:00:24,500 --> 00:00:25,870
Rule number is public.

8
00:00:25,880 --> 00:00:27,620
And ages private.

9
00:00:28,250 --> 00:00:34,830
So let's add one more function to this class and let's make that function public.

10
00:00:34,910 --> 00:00:44,380
So I have a public function the name of the function is let's say display so what this function will

11
00:00:44,380 --> 00:00:48,250
do is it will print the age and it will number of the student.

12
00:00:49,060 --> 00:00:58,110
So a return type will be void C out age space and and but

13
00:01:01,300 --> 00:01:04,020
so this function displays the H.

14
00:01:04,030 --> 00:01:08,890
And rule number of the student return type will be void.

15
00:01:08,890 --> 00:01:12,980
Okay now let's discuss how to call this function.

16
00:01:13,240 --> 00:01:19,930
So we will call this function using the dot operator just as we use dot operator to access the properties

17
00:01:20,200 --> 00:01:24,590
we can use dot operator to access or to call the function.

18
00:01:24,640 --> 00:01:31,310
So for property what we used to do is object name dot property name for calling a function object name

19
00:01:31,330 --> 00:01:33,190
dot function name.

20
00:01:33,220 --> 00:01:33,820
Okay.

21
00:01:33,920 --> 00:01:39,780
So S1 so S1 dot uh what is the name of the function.

22
00:01:39,790 --> 00:01:43,600
Display s under display.

23
00:01:43,600 --> 00:01:53,230
Similarly we can call as to dot display and let's call display function for S6 as well.

24
00:01:56,290 --> 00:02:04,290
Starred as six dot display okay.

25
00:02:04,490 --> 00:02:15,690
And let's write short also for a six so a six arrow display and that's all okay.

26
00:02:15,820 --> 00:02:18,460
So this is the V to call a function.

27
00:02:18,490 --> 00:02:25,180
Now our function is not thinking any argument if our function takes our argument we can positing fantasies

28
00:02:25,500 --> 00:02:29,890
since our function doesn't take any argument our identities are empty.

29
00:02:30,110 --> 00:02:40,060
Okay so now what I want to do is uh I want to use this each property outside the class.

30
00:02:40,260 --> 00:02:42,030
This is properties private.

31
00:02:42,270 --> 00:02:47,520
So my question is how to access a private property outside the class.

32
00:02:47,520 --> 00:02:50,610
So the answer is using a function.

33
00:02:50,610 --> 00:02:58,170
So let's make one more public function uh written by will be in danger and the name of the function

34
00:02:58,170 --> 00:02:58,410
is.

35
00:02:58,410 --> 00:03:02,220
Get each.

36
00:03:02,240 --> 00:03:10,840
So this is a public function but this function will do is it will done each age is a private property.

37
00:03:10,840 --> 00:03:19,380
So what is happening now here is see this get page function is a public function.

38
00:03:19,480 --> 00:03:25,610
So since this is a public function we can call it from the other file that is from the student does

39
00:03:25,650 --> 00:03:27,250
not CPB.

40
00:03:27,340 --> 00:03:34,740
So we can call this function and this cottage function will return us each whereas age is a private.

41
00:03:35,150 --> 00:03:35,630
Okay.

42
00:03:35,710 --> 00:03:41,950
So with the help of this public function we can get the value of private function.

43
00:03:41,950 --> 00:03:45,530
Now let's see called.

44
00:03:45,610 --> 00:03:48,220
So this is our file.

45
00:03:48,370 --> 00:03:55,970
Uh what I want to do is uh see out S1 age

46
00:03:58,660 --> 00:04:03,920
s dart we will call the function get age get data is a public function.

47
00:04:04,450 --> 00:04:07,110
So no compulsion that I will be there.

48
00:04:07,420 --> 00:04:12,040
And similarly let's uh do it for this to as well so see out

49
00:04:15,130 --> 00:04:16,330
as to age

50
00:04:20,110 --> 00:04:22,960
as to dart get garbage

51
00:04:28,220 --> 00:04:33,400
OK let's add an on line here OK.

52
00:04:33,400 --> 00:04:34,390
Everything seems fine.

53
00:04:34,390 --> 00:04:34,660
No

54
00:04:38,210 --> 00:04:42,400
so one more thing uh we can only access the age.

55
00:04:42,410 --> 00:04:43,760
We cannot set the age.

56
00:04:43,820 --> 00:04:48,590
So if we will run this program we will get compilation error saying that this age property is private.

57
00:04:48,710 --> 00:04:49,950
So you cannot access them.

58
00:04:50,480 --> 00:04:57,590
So let's make uh let's come on get out age and age.

59
00:04:58,710 --> 00:04:58,970
Okay.

60
00:04:58,980 --> 00:05:01,680
So now what program will run fine.

61
00:05:01,740 --> 00:05:03,180
Okay so let's run our program

62
00:05:06,440 --> 00:05:12,040
Okay so the submitter is found out display what is the arrows.

63
00:05:12,900 --> 00:05:16,710
Glass rent has no member named display.

64
00:05:16,710 --> 00:05:18,840
Oh uh.

65
00:05:18,990 --> 00:05:22,010
We also have to run this file because we did genius to this file.

66
00:05:22,020 --> 00:05:24,630
So this file should also be run now.

67
00:05:24,720 --> 00:05:30,060
Uh see out age and lumber.

68
00:05:30,200 --> 00:05:31,200
Oh it is that is

69
00:05:35,380 --> 00:05:37,290
CO2 is not declared in this code.

70
00:05:37,750 --> 00:05:44,470
So the error is uh this see out the functionality of the C out is defined in your stream file so I have

71
00:05:44,470 --> 00:05:45,880
to include I Ustream here.

72
00:05:53,300 --> 00:05:54,310
Mm hmm.

73
00:05:54,340 --> 00:05:55,130
Again it is.

74
00:05:56,180 --> 00:05:59,760
Okay so this line is defined in namespace.

75
00:06:00,580 --> 00:06:08,580
So namespace the.

76
00:06:08,720 --> 00:06:10,010
Now this is fine.

77
00:06:10,090 --> 00:06:11,250
Uh let's send this file.

78
00:06:12,820 --> 00:06:15,490
So ages private.

79
00:06:16,410 --> 00:06:16,680
Okay.

80
00:06:16,690 --> 00:06:23,900
So we also have to come into it out here and also we have to come into get out

81
00:06:26,660 --> 00:06:29,180
and is this seems fine.

82
00:06:29,180 --> 00:06:34,460
Okay so let's print let's get dates for Essex also.

83
00:06:34,460 --> 00:06:36,960
So see old Essex

84
00:06:39,900 --> 00:06:42,130
six not get each

85
00:06:45,060 --> 00:06:46,210
thing everything is fine now.

86
00:06:46,290 --> 00:06:46,970
Let's start now.

87
00:06:46,990 --> 00:06:54,280
But now let's run this and now we will run this six year dynamic.

88
00:06:54,510 --> 00:07:00,420
So for dynamic we have to use data fence celebrated and now let's send this file

89
00:07:04,100 --> 00:07:06,110
seems like everything is running fine

90
00:07:09,870 --> 00:07:10,110
okay.

91
00:07:10,110 --> 00:07:12,140
So let us analyse the output.

92
00:07:12,840 --> 00:07:16,460
So first of all uh the call the display function.

93
00:07:16,710 --> 00:07:20,510
So display function will print that each and the usual number.

94
00:07:20,520 --> 00:07:28,760
So this is the age which is a random value because we have not set it and this is under because we certainly

95
00:07:28,880 --> 00:07:30,340
number two we entered.

96
00:07:30,340 --> 00:07:30,960
Okay.

97
00:07:31,000 --> 00:07:34,010
So after S1 the print is too.

98
00:07:34,120 --> 00:07:40,600
So if it is true we didn't set any values about the values that got the beach and then we are getting

99
00:07:40,690 --> 00:07:46,690
that H for this on that each for this one is this it is a random value because it is a private field

100
00:07:46,690 --> 00:07:49,930
and we have not make of public function to set it.

101
00:07:50,050 --> 00:07:54,380
Similarly as two ages also a garbage value because we haven't said it.

102
00:07:54,760 --> 00:08:03,210
And then S1 daughter number which we said to be hundred and after that exit door.

103
00:08:03,290 --> 00:08:06,530
We said that all number for a six and a six star display.

104
00:08:07,070 --> 00:08:16,650
So for a six the ages that number Lou and that number is tardy because we said it then again we six.

105
00:08:16,690 --> 00:08:18,700
Then again uh display function.

106
00:08:18,700 --> 00:08:21,120
So both are the same.

107
00:08:21,280 --> 00:08:27,610
And then we got the H for Essex so each for Essex is at random value.

108
00:08:27,700 --> 00:08:35,660
Okay so the output is expected output is what we expected.

109
00:08:35,840 --> 00:08:43,690
So instead of like using the lead fence operator and the DART Operator we can directly write Essex had

110
00:08:43,790 --> 00:08:44,360
a wage

111
00:08:51,140 --> 00:08:51,550
Yeah.

112
00:08:51,650 --> 00:08:52,600
It's working fine.

113
00:08:56,540 --> 00:08:56,880
Okay.

114
00:08:56,900 --> 00:09:01,590
So so now I can read the property of a private field.

115
00:09:01,590 --> 00:09:06,130
So if I can read it then they should also be happy to read it.

116
00:09:06,150 --> 00:09:12,480
So for reading the press or for writing the uh private property what we can do is we can create a function

117
00:09:13,170 --> 00:09:26,540
void stage so this stage function will take age as input and it will set age to a and that's all.

118
00:09:26,560 --> 00:09:28,820
Okay so let's come to this class.

119
00:09:28,850 --> 00:09:32,620
So this class is like we will get confused using this class.

120
00:09:32,620 --> 00:09:36,370
So I created a new class student new DA CPB.

121
00:09:36,370 --> 00:09:38,310
So now we will do the work here.

122
00:09:38,350 --> 00:09:42,210
So for doing something first of all we have to create object.

123
00:09:42,250 --> 00:09:43,690
So let's create two objects.

124
00:09:43,690 --> 00:09:46,270
One is starting and that one is dynamic.

125
00:09:46,270 --> 00:09:47,810
So Student 1.

126
00:09:47,890 --> 00:09:50,000
Now let's create a dynamic object.

127
00:09:50,110 --> 00:09:52,920
STUDENT As to new student

128
00:09:56,420 --> 00:10:02,960
so for this student to work we also have to include the file here so hashing include

129
00:10:06,230 --> 00:10:11,160
student art CPB.

130
00:10:11,250 --> 00:10:23,920
Okay so now let's set the age and then we will display so as are not stage oh now let's say a stage

131
00:10:24,010 --> 00:10:26,300
and let's say the value is 20.

132
00:10:26,440 --> 00:10:36,760
Similarly for as to as to Edwidge so the S2 0 stage and let's say 30.

133
00:10:36,970 --> 00:10:38,950
Now let's call as our display

134
00:10:41,530 --> 00:10:47,980
and as to add or display.

135
00:10:48,120 --> 00:10:50,940
Okay so now let us run our program

136
00:10:54,660 --> 00:11:03,050
so as not set age there is something wrong with it glass front has no members her age or I again did

137
00:11:03,060 --> 00:11:04,080
the same mistake.

138
00:11:04,080 --> 00:11:10,090
I have to run this file because I did 10 years to this file so this green line means that these men

139
00:11:10,150 --> 00:11:15,430
alignment of lines I already compiled and this yellow lines means the area to be compiled so called

140
00:11:15,500 --> 00:11:26,390
Lux's so called logs also help us so now a venue will render program this whole code will become green.

141
00:11:26,480 --> 00:11:28,650
See now everything is compiled.

142
00:11:28,910 --> 00:11:29,960
Now it will work.

143
00:11:29,960 --> 00:11:30,950
It will not draw any other

144
00:11:33,700 --> 00:11:37,100
so ages 20 and the roll number is garbage value.

145
00:11:37,120 --> 00:11:37,860
A just 30.

146
00:11:37,880 --> 00:11:39,250
Rule number is the garbage value

147
00:11:44,420 --> 00:11:51,000
so in this way we can like we can get the property and we can also set the property.

148
00:11:51,110 --> 00:11:51,410
Okay.

149
00:11:51,420 --> 00:11:52,340
A private property.

150
00:11:52,910 --> 00:11:59,790
So one question that will be coming to her mind is what is the use of making each a private field.

151
00:12:00,110 --> 00:12:05,560
If we can't read and write it then basically what did we achieved by making it private.

152
00:12:05,570 --> 00:12:08,120
What is the reason for making something private.

153
00:12:08,630 --> 00:12:17,090
So look carefully we cannot change the age radically because it's a private field but we have to call

154
00:12:17,180 --> 00:12:23,360
a function get age or set age to access the private property age.

155
00:12:23,450 --> 00:12:31,100
Okay so now let's take an example to illustrate to the benefit of private let's say I want to put a

156
00:12:31,100 --> 00:12:35,020
constraint on age that age cannot be negative.

157
00:12:35,390 --> 00:12:39,620
If age would have been public then anyone can set it to be minus one.

158
00:12:39,620 --> 00:12:42,200
How as one dot age equals minus one.

159
00:12:42,230 --> 00:12:47,240
And it would have been Vogue if the age was public but now the age is private.

160
00:12:47,300 --> 00:12:50,680
So I can put a constraint here before starting the age.

161
00:12:50,990 --> 00:13:01,140
What I will do I will check if the input is less than zero then simply done do not do anything.

162
00:13:01,140 --> 00:13:07,600
Simply written we are not setting age okay so we can add constraint like this.

163
00:13:07,680 --> 00:13:10,750
So this is the use of private property.

164
00:13:10,830 --> 00:13:15,870
What we will do we will make a public function to access the private property.

165
00:13:15,900 --> 00:13:18,360
So now here we can add constraint.

166
00:13:18,360 --> 00:13:24,960
For example like uh if you want to add more constraint like there should be a password you have to give

167
00:13:24,960 --> 00:13:32,900
password as well for setting age basically an authorized person can notarized person can only set age.

168
00:13:33,030 --> 00:13:36,990
So let's say the password is 1 2 3.

169
00:13:37,110 --> 00:13:46,870
So if password is articles 2 1 2 3 if password is not mandatory then do not do anything simpler then.

170
00:13:46,920 --> 00:13:47,770
Okay.

171
00:13:48,000 --> 00:13:54,110
So now we got the property to add the constraint we get the power to add the constraint.

172
00:13:54,270 --> 00:13:57,380
So I can add multiple constraints here.

173
00:13:57,780 --> 00:14:01,050
So whenever you are working in a real world project.

174
00:14:01,320 --> 00:14:06,870
If a property is important that is a third person should not be allowed to use the property.

175
00:14:06,870 --> 00:14:09,780
So we should make those properties private.

176
00:14:10,020 --> 00:14:13,790
Okay so this is a good function.

177
00:14:13,800 --> 00:14:16,830
This is a third function get function.

178
00:14:16,830 --> 00:14:20,240
We can read and with the help of said function we can write.

179
00:14:20,340 --> 00:14:26,070
So we generally call it get a function and set the function getter and setter with the help of get the

180
00:14:26,070 --> 00:14:27,000
function.

181
00:14:27,000 --> 00:14:33,060
We will get the data with the help of the function we can said that you do okay.

182
00:14:33,300 --> 00:14:33,690
Thank you.
