1
00:00:01,080 --> 00:00:02,010
Hello everyone.

2
00:00:02,010 --> 00:00:07,760
So in the last video we started discussing about whoops we learned what is whoops.

3
00:00:07,800 --> 00:00:13,180
Object Oriented Programming Baghdad object and how we can create glasses.

4
00:00:13,260 --> 00:00:21,980
So in this video we will see how to create objects and how to access its properties so in the last video

5
00:00:22,100 --> 00:00:23,890
we created this class.

6
00:00:23,930 --> 00:00:26,070
And we know how to create glasses.

7
00:00:26,090 --> 00:00:29,660
So now let's see how to create object of this class

8
00:00:32,910 --> 00:00:44,890
so when we write so when we write in a is the name of the variable and a is of type in digit.

9
00:00:44,930 --> 00:00:46,850
Now we have a class student

10
00:00:51,070 --> 00:00:55,090
this student has two properties age and William.

11
00:00:55,090 --> 00:01:00,540
But now I want to create object S1.

12
00:01:00,580 --> 00:01:10,410
Now I want to create a student or I can say I want to create a variable S1 of type student.

13
00:01:10,520 --> 00:01:17,120
How can we say that because glasses nothing but a user defined data type

14
00:01:19,890 --> 00:01:29,170
that another name of glasses user defined data type for example and double floored.

15
00:01:29,270 --> 00:01:40,180
These all are built into the types building types whereas class is a user defined data type okay.

16
00:01:40,370 --> 00:01:54,890
So when we write in a is the name of the variable but when we write student S1 S1 is the name of the

17
00:01:54,890 --> 00:01:56,150
object here.

18
00:01:56,180 --> 00:01:57,760
We will call it a variable.

19
00:01:57,890 --> 00:02:06,080
And here we will call it the object a is of type in digit S1 is of type student.

20
00:02:06,110 --> 00:02:06,550
Okay.

21
00:02:06,650 --> 00:02:07,390
So a student.

22
00:02:07,430 --> 00:02:12,280
Class glasses nothing but the user defined data type.

23
00:02:12,350 --> 00:02:21,530
So let's see when we write in into what will happen we will get four blocks of memory space and the

24
00:02:21,530 --> 00:02:23,350
name of this block is a.

25
00:02:23,770 --> 00:02:24,080
Okay.

26
00:02:24,080 --> 00:02:35,510
And there will be random values random garbage value so when we write student S1 we will get a memory

27
00:02:35,510 --> 00:02:45,070
block the name of this block is S1 and virtual boot size so student contain two integers.

28
00:02:45,120 --> 00:02:49,410
Rule number and age both our 44 bytes.

29
00:02:49,410 --> 00:02:55,870
So in total eight bytes so the size of this block will be approximately eight bytes not exactly.

30
00:02:55,910 --> 00:03:01,410
It byte because there are many other things also we do not need to understand them yet.

31
00:03:01,440 --> 00:03:06,930
Okay so this is nearly eight bytes approximately eight bytes but not exactly it bytes.

32
00:03:07,050 --> 00:03:14,010
So S1 will contain H and it will have rule number and garbage values.

33
00:03:14,040 --> 00:03:14,370
Okay.

34
00:03:14,680 --> 00:03:18,750
Similarly when we write in day there was garbage values.

35
00:03:18,780 --> 00:03:24,390
So similarly when we create an object there will be garbage values.

36
00:03:24,390 --> 00:03:34,330
Similarly we can create an understood end student as to again we will get approximately eight bites

37
00:03:34,330 --> 00:03:39,490
of memory space name is as to age and a number.

38
00:03:40,270 --> 00:03:53,490
And similarly garbage value Okay so till now we have created objects statically below we are creating

39
00:03:53,490 --> 00:03:58,530
objects strategically but we can also create objects dynamically

40
00:04:01,690 --> 00:04:06,310
so in the static how we create objects practically in.

41
00:04:07,040 --> 00:04:07,750
Okay.

42
00:04:07,960 --> 00:04:14,310
Student S1 student S2

43
00:04:17,190 --> 00:04:18,180
So what will happen.

44
00:04:18,180 --> 00:04:27,800
Like student s when is it s containing age and rule number garbage values so why garbage values.

45
00:04:28,040 --> 00:04:33,440
Because we are not setting the properties ourself below that's why garbage values.

46
00:04:33,440 --> 00:04:39,670
Similarly for Sudan to age rule number garbage values

47
00:04:43,620 --> 00:04:50,630
Okay now let's see how we can create objects dynamically so for creating an integer dynamically the

48
00:04:50,660 --> 00:04:55,840
same indexes into start a new and

49
00:04:58,860 --> 00:04:59,190
the.

50
00:04:59,340 --> 00:05:02,700
So this is this index for creating an integer.

51
00:05:02,790 --> 00:05:04,040
Benny Michaeli.

52
00:05:04,220 --> 00:05:14,600
So what will happen in the heap memory we will get for bytes of memory space and in the static memory.

53
00:05:14,600 --> 00:05:17,600
This is the name of the variable e and efforts.

54
00:05:17,630 --> 00:05:21,030
This is handed down and it will be here.

55
00:05:21,020 --> 00:05:23,990
Okay so this is static memory

56
00:05:27,360 --> 00:05:36,300
and this one is he similarly if we want to create an object dynamically the syntax will be similar to

57
00:05:36,300 --> 00:05:38,940
this one we will write student

58
00:05:41,590 --> 00:05:54,310
then start as t is new keyword and then the data type which is student So what will happen in the heap

59
00:05:54,320 --> 00:05:55,380
memory.

60
00:05:55,910 --> 00:06:08,180
We will get nearly eight bytes and this will have each rule number garbage value and in the state in

61
00:06:08,180 --> 00:06:15,400
the static memory we will get eight bytes of memory space because as TS a point.

62
00:06:15,420 --> 00:06:23,180
Similarly the size of A's eared bytes because it's a pointer and let's say for there this is 300.

63
00:06:23,270 --> 00:06:25,350
So this will contain 300.

64
00:06:26,650 --> 00:06:29,440
Okay this will contently entered

65
00:06:33,930 --> 00:06:34,320
okay.

66
00:06:34,430 --> 00:06:39,130
So what we used to do with the variables we can also do with objects.

67
00:06:39,140 --> 00:06:40,640
Now let's sing called

68
00:06:47,690 --> 00:06:53,040
so let's create object statically

69
00:07:04,720 --> 00:07:12,940
so we can create many object student as to similarly we can create many objects in one line like we

70
00:07:12,940 --> 00:07:21,050
used to do with variables so as tree as food as 5 and so on.

71
00:07:21,050 --> 00:07:27,140
Now let's create object dynamically so creating objects dynamically

72
00:07:31,760 --> 00:07:34,250
so this index is quite similar.

73
00:07:34,690 --> 00:07:43,100
So student start as six as new keyword and then later type which is student

74
00:07:47,290 --> 00:07:51,860
now let's see how we can set the property of an object.

75
00:07:56,760 --> 00:08:05,020
Okay so we have an object S1 S1 contain H.

76
00:08:05,020 --> 00:08:05,980
And rule number

77
00:08:08,940 --> 00:08:10,900
and garbage of ideas.

78
00:08:11,190 --> 00:08:20,090
Similarly we have object as to age rule number garbage value.

79
00:08:20,980 --> 00:08:23,220
And let's take one dynamic object.

80
00:08:23,620 --> 00:08:28,870
So this is s.t..

81
00:08:29,100 --> 00:08:39,070
Now this is our heat memory and here we have each and William but which contain garbage values.

82
00:08:39,140 --> 00:08:48,850
Okay so when we write and a word will happen we will get four bytes of memory space.

83
00:08:48,880 --> 00:08:58,240
Now if we want to put something inside this box what we will do we will write a equals five so five

84
00:08:58,240 --> 00:08:59,280
will come here.

85
00:08:59,320 --> 00:09:06,360
Now similarly if I want to write something here what I can do is one equals.

86
00:09:06,790 --> 00:09:15,960
24 now is it right or wrong it is wrong because S1 one contain multiple properties if I want to set

87
00:09:16,050 --> 00:09:23,160
each this index will be as one dot each equals 24.

88
00:09:23,220 --> 00:09:24,510
Now this is right.

89
00:09:24,510 --> 00:09:26,460
So 24 will come here.

90
00:09:26,460 --> 00:09:27,930
This value will become 24.

91
00:09:28,350 --> 00:09:35,370
Similarly I can central number s one dot rule number is let's say a hundred.

92
00:09:35,370 --> 00:09:38,080
So this value will become a hundred.

93
00:09:38,080 --> 00:09:46,900
Okay so syntax is very simple so what we have to right this is object name dot property name.

94
00:09:47,040 --> 00:09:47,800
Okay.

95
00:09:47,930 --> 00:09:55,650
Object name dot property name.

96
00:09:55,700 --> 00:09:56,750
Now let's see in code

97
00:10:01,660 --> 00:10:19,250
as one dot age let's say 24 S1 DOT rule number let's say a hundred and similarly we can also print c

98
00:10:19,340 --> 00:10:21,320
out as rendered age

99
00:10:25,430 --> 00:10:28,850
C out as one dot.

100
00:10:28,850 --> 00:10:30,150
Rule number.

101
00:10:30,470 --> 00:10:35,140
Okay so this is a very simple index to access the properties of an object.

102
00:10:37,420 --> 00:10:44,740
Now let us talk about how to access properties of our dynamically created object.

103
00:10:44,740 --> 00:10:52,120
So we have object S6 which is dynamically created sorry.

104
00:10:52,210 --> 00:10:52,950
Wait a second

105
00:10:56,930 --> 00:11:00,280
so if we have an integer variable which is dynamically created.

106
00:11:00,290 --> 00:11:04,220
So what will be the situation and star.

107
00:11:04,240 --> 00:11:17,310
A is new and so this is it bytes pointer and this is our 4 bytes memory space so we cannot write simply

108
00:11:17,340 --> 00:11:18,380
equals 5.

109
00:11:18,420 --> 00:11:19,890
This is wrong.

110
00:11:19,890 --> 00:11:25,410
The right way to do is first we have to reach in this box now for reaching this box.

111
00:11:25,410 --> 00:11:28,090
We will use R to start R D defense operator.

112
00:11:28,140 --> 00:11:31,620
So start is five now five will come here.

113
00:11:31,800 --> 00:11:37,630
Similarly in case of dynamic created object we will do something similar to this.

114
00:11:37,830 --> 00:11:42,010
So we have object S6 which is dynamically created.

115
00:11:42,210 --> 00:11:57,760
So S6 is new student Okay so this is a pointer of eight bytes and now this box contain H and lumber

116
00:11:58,660 --> 00:12:00,940
which are garbage initially.

117
00:12:00,940 --> 00:12:04,410
Okay so we cannot write a six dot age.

118
00:12:04,720 --> 00:12:06,080
This is wrong.

119
00:12:06,430 --> 00:12:10,320
What it will do is it will go to a six and inside a six.

120
00:12:10,330 --> 00:12:15,620
It will try to find each but it is present in this box.

121
00:12:15,700 --> 00:12:17,190
Age is present in this box.

122
00:12:17,260 --> 00:12:20,460
So we have to reach this box for it in this box.

123
00:12:20,500 --> 00:12:22,440
We will use data fence operator.

124
00:12:22,450 --> 00:12:27,240
So start S6 by doing statistics.

125
00:12:27,260 --> 00:12:35,100
We have reached this at this box dot age let's say 5 now 5 will come here.

126
00:12:35,260 --> 00:12:44,860
Similarly star as 6 Dato number let's add 200 so two hundred will come here.

127
00:12:44,860 --> 00:12:51,150
Okay so in case of four dynamically created objects we have to use data fence operator to reach this

128
00:12:51,150 --> 00:12:54,730
box okay so let's good

129
00:13:00,170 --> 00:13:04,720
we have to use star operator so start A6

130
00:13:10,700 --> 00:13:14,530
last age twenty three

131
00:13:17,370 --> 00:13:20,660
is six Natali numbers

132
00:13:23,970 --> 00:13:27,410
let's say 30 okay.

133
00:13:27,720 --> 00:13:28,350
Now this is.

134
00:13:29,840 --> 00:13:30,740
Now we have all.

135
00:13:30,740 --> 00:13:33,030
Now we also have a shortcut to do this.

136
00:13:33,100 --> 00:13:45,900
We will write a six and a each is 23 A6 and orderly number is 30.

137
00:13:46,950 --> 00:13:59,160
Okay so these two lines and these two lines that exactly seem uh exactly same means uh if we will right

138
00:13:59,670 --> 00:14:07,710
start Essex dot age and we will write a six note age ethics arrow age.

139
00:14:07,940 --> 00:14:09,680
So these two are exactly same

140
00:14:12,630 --> 00:14:14,220
this arrow is a shortcut.

141
00:14:14,220 --> 00:14:19,420
Okay this is a shortcut they will exactly Wuxi.

142
00:14:19,660 --> 00:14:21,070
But this is a shortcut.

143
00:14:21,070 --> 00:14:22,370
Many people use it.

144
00:14:23,380 --> 00:14:30,340
Instead of using stored and then dart and then brackets and all that stuff it is much simpler to use

145
00:14:30,640 --> 00:14:34,300
ETL okay.

146
00:14:34,840 --> 00:14:35,230
Now

147
00:14:38,920 --> 00:14:43,660
if we will run this file we will get a lot of errors.

148
00:14:43,670 --> 00:14:44,320
Let's see why

149
00:14:47,890 --> 00:14:48,160
okay.

150
00:14:48,170 --> 00:14:53,410
So I am telling you if we will run this file we will get a lot of errors.

151
00:14:53,660 --> 00:15:02,430
So let's see so we are getting a completion edit and let's see that ID.

152
00:15:02,740 --> 00:15:08,710
So this is dated ages private roll number is private.

153
00:15:08,790 --> 00:15:10,490
Age is private.

154
00:15:10,510 --> 00:15:11,680
Again age is private.

155
00:15:11,890 --> 00:15:13,150
So we are getting something.

156
00:15:13,210 --> 00:15:17,130
So we are getting an error which is telling us that age.

157
00:15:17,150 --> 00:15:18,980
Roland but these are private.

158
00:15:19,030 --> 00:15:21,900
Now let's see what is private.

159
00:15:22,240 --> 00:15:36,260
So there is a concept in Opes called access modifiers excess modifiers so excess modifiers is who all

160
00:15:36,260 --> 00:15:39,740
can access the properties and functions of a class.

161
00:15:39,740 --> 00:15:40,180
Okay.

162
00:15:40,250 --> 00:15:48,830
So there are two types of excess modifier public private and the third one is predicted

163
00:15:53,870 --> 00:15:56,490
so we will not discuss about protected yet.

164
00:15:56,540 --> 00:15:58,970
We will discuss about public and private.

165
00:15:59,210 --> 00:16:06,280
So what private uses private will say you can access properties of a class inside the class only.

166
00:16:06,280 --> 00:16:06,920
Okay.

167
00:16:07,010 --> 00:16:16,840
So I would say as you can access the properties only inside the class what we are doing here is C H.

168
00:16:16,870 --> 00:16:23,450
Andrew Lambert can only be accessed within student class letters is between this bracket and this record

169
00:16:29,980 --> 00:16:32,940
private will say this to fields.

170
00:16:32,960 --> 00:16:41,080
Rule number and age can only be accessed within the student class that is between this bracket and this

171
00:16:41,080 --> 00:16:41,560
bracket.

172
00:16:42,280 --> 00:16:42,570
Okay

173
00:16:45,490 --> 00:16:53,380
what public says is if the access modified is public then you can use the properties of the class anywhere

174
00:16:53,870 --> 00:16:55,120
anywhere in your program.

175
00:16:55,160 --> 00:16:57,350
You can use the properties of the class.

176
00:16:57,920 --> 00:17:03,700
Whereas if the access modified is private you can use the properties inside the class only.

177
00:17:04,070 --> 00:17:11,810
So here we are when we created these two variables these two properties we have not defined any access

178
00:17:11,890 --> 00:17:15,770
modifier so by default the access modifier is private.

179
00:17:16,610 --> 00:17:24,740
Okay so default access modifier is private if you will not specify the access modify it.

180
00:17:24,890 --> 00:17:26,070
Default will be private.

181
00:17:26,600 --> 00:17:29,700
So here rule number n h by default they are private.

182
00:17:29,720 --> 00:17:38,630
And what I'm doing here is C I am using excess I am using each and lumber outside the class in the main

183
00:17:38,630 --> 00:17:41,080
function I am using each and number.

184
00:17:41,150 --> 00:17:46,280
That's why we are getting a compilation error which is saying that rule number n h are private and you

185
00:17:46,280 --> 00:17:48,740
cannot use them outside the class.

186
00:17:48,740 --> 00:17:51,000
Similarly we are using a general number here.

187
00:17:51,430 --> 00:17:51,960
Okay.

188
00:17:52,010 --> 00:17:58,430
So what we have to do if we will if I want to use the properties of the class outside the class we have

189
00:17:58,430 --> 00:18:00,020
to make them public.

190
00:18:00,200 --> 00:18:02,560
So for public work we will do.

191
00:18:02,760 --> 00:18:04,420
There is a very simple index.

192
00:18:04,430 --> 00:18:10,200
We just have to write the keyword public so we will use.

193
00:18:10,230 --> 00:18:14,220
We will write the keyword public and then column.

194
00:18:14,220 --> 00:18:16,410
So after writing public column what will happen

195
00:18:21,730 --> 00:18:29,260
so after writing public everything everything below public will become public.

196
00:18:29,260 --> 00:18:35,620
So now rule number and age they are public and now this line is correct this line is correct.

197
00:18:35,620 --> 00:18:39,220
Basically we will not get any uh any compulsion at it.

198
00:18:40,020 --> 00:18:40,470
Okay.

199
00:18:40,510 --> 00:18:49,490
Now let's see how come by lament program so we are getting ahead.

200
00:18:49,620 --> 00:18:50,550
So what is the idea.

201
00:18:50,640 --> 00:18:51,770
Okay.

202
00:18:51,960 --> 00:18:56,050
This Beckett it's right now

203
00:18:59,570 --> 00:19:01,130
see how program is running

204
00:19:06,320 --> 00:19:06,700
okay.

205
00:19:06,720 --> 00:19:08,370
Now what if

206
00:19:11,040 --> 00:19:13,720
I make in Deja each private.

207
00:19:13,860 --> 00:19:16,880
So private.

208
00:19:17,200 --> 00:19:18,160
Now what will happen now

209
00:19:22,670 --> 00:19:28,760
so when you write public everything inside public will become public.

210
00:19:28,850 --> 00:19:30,200
So this rule number is public.

211
00:19:30,470 --> 00:19:34,460
But now we have defined and another access modifier which is private.

212
00:19:34,460 --> 00:19:36,560
So now age is private.

213
00:19:36,560 --> 00:19:42,890
So it can only be used between this and this blanket that is each can only be used inside.

214
00:19:42,890 --> 00:19:47,300
Class and the but can be used any weird

215
00:19:50,160 --> 00:19:53,030
so as one dot age is 24.

216
00:19:53,030 --> 00:19:54,940
This line is correct because.

217
00:19:54,950 --> 00:19:55,290
Sorry.

218
00:19:55,290 --> 00:20:02,130
This line is wrong because age is private but this line is correct.

219
00:20:02,160 --> 00:20:02,630
Why.

220
00:20:02,640 --> 00:20:05,490
Because it is public.

221
00:20:05,490 --> 00:20:06,480
Rule number is public.

222
00:20:06,480 --> 00:20:07,490
Age is private.

223
00:20:07,620 --> 00:20:13,030
So we will get compilation error wherever we have used each and outside the class.

224
00:20:13,110 --> 00:20:15,590
Let's come bilateral program.

225
00:20:16,050 --> 00:20:21,990
Now this time if you will see that ad that it will be only due to age ages private ages private ages

226
00:20:21,990 --> 00:20:25,400
private there will be no added regarding the roll number.

227
00:20:25,410 --> 00:20:27,220
Okay.

228
00:20:27,360 --> 00:20:33,900
So this way we can use like we can define multiple access modifiers.

229
00:20:33,900 --> 00:20:34,580
Okay.

230
00:20:34,830 --> 00:20:36,710
Now I want to show you one more thing.

231
00:20:42,920 --> 00:20:46,670
Let's remove this called okay.

232
00:20:46,780 --> 00:20:49,820
Uh let's remove everything else

233
00:21:25,900 --> 00:21:26,230
okay.

234
00:21:26,260 --> 00:21:33,330
So what I did it is I uh I'm creating a lot I care to file student do you start CPB.

235
00:21:33,820 --> 00:21:37,600
And this is I want all the class which is containing the class only.

236
00:21:37,750 --> 00:21:39,310
Now why I am doing this is

237
00:21:43,090 --> 00:21:51,730
see these are concept in software development which is called isolation of logic so overt isolation

238
00:21:51,730 --> 00:21:58,070
of logic seizes whenever you want to create a class create a class in a separate file.

239
00:21:58,240 --> 00:22:00,420
So we will have a file.

240
00:22:00,520 --> 00:22:06,910
Now this file will create the class and we will have another file in this file.

241
00:22:06,910 --> 00:22:11,620
We will use this class use class here okay.

242
00:22:11,750 --> 00:22:16,370
So it's like best practice in the software in the software industry.

243
00:22:19,020 --> 00:22:21,810
Because the logic is different.

244
00:22:21,810 --> 00:22:24,420
Here we are here we will just define the class.

245
00:22:24,450 --> 00:22:26,410
And here we will use class.

246
00:22:26,460 --> 00:22:28,360
So I did exactly the same.

247
00:22:28,380 --> 00:22:28,820
Okay.

248
00:22:28,920 --> 00:22:35,350
So I have a class which is student and I have entered the class and I have another file student.

249
00:22:35,370 --> 00:22:36,350
You start TPB here.

250
00:22:36,450 --> 00:22:39,300
We are using the student class.

251
00:22:39,320 --> 00:22:43,790
Now if I will run this program it will to me and added model with data.

252
00:22:43,830 --> 00:22:47,030
It will say I don't know what is student why.

253
00:22:47,130 --> 00:22:49,950
Because student is defined in a separate file.

254
00:22:49,950 --> 00:22:57,600
So if I want to use student in this file right what I have to use I have to include that file in this

255
00:22:57,690 --> 00:22:58,580
in this current file.

256
00:22:58,950 --> 00:23:10,150
So hashing glued downloaded commas name of the file student art CPB okay.

257
00:23:10,220 --> 00:23:11,950
Now this is correct.

258
00:23:11,960 --> 00:23:12,600
Now let's start.

259
00:23:12,770 --> 00:23:13,910
Now let's turn our program

260
00:23:17,120 --> 00:23:17,370
okay.

261
00:23:17,380 --> 00:23:18,900
So this is training me at it.

262
00:23:18,990 --> 00:23:20,890
Uh what is the error.

263
00:23:20,890 --> 00:23:22,180
Let me see.

264
00:23:25,900 --> 00:23:27,420
And funds in danger.

265
00:23:27,460 --> 00:23:28,120
Private.

266
00:23:28,700 --> 00:23:33,870
Oh I have to run this class also.

267
00:23:34,010 --> 00:23:34,440
Now this.

268
00:23:34,520 --> 00:23:40,380
Now this will be correct see it is running now.

269
00:23:41,750 --> 00:23:42,450
Okay.

270
00:23:42,570 --> 00:23:45,170
So always this is a good practice.

271
00:23:45,170 --> 00:23:49,040
Make glass and separate file and use data class in your current file.

272
00:23:50,590 --> 00:23:53,010
Now.

273
00:23:54,070 --> 00:24:04,290
Now when we included I use gym class I used this ad was for I use string but then I used but when I

274
00:24:04,290 --> 00:24:12,180
included student file I used the downloaded data commas because for Ford built in files the files which

275
00:24:12,190 --> 00:24:15,730
are already present we have to use these arrows.

276
00:24:15,900 --> 00:24:22,560
But if we create a fly file on our own that is user file the file that we have created we have to use

277
00:24:22,770 --> 00:24:23,750
devil records.

278
00:24:24,090 --> 00:24:24,350
Okay.

279
00:24:24,360 --> 00:24:25,700
This is just a syntax.

280
00:24:25,710 --> 00:24:26,940
Nothing else.

281
00:24:26,970 --> 00:24:27,790
Okay.

282
00:24:27,810 --> 00:24:29,310
So thank you.
