1
00:00:01,450 --> 00:00:02,200
Hello everyone.

2
00:00:02,200 --> 00:00:07,890
So today we will learn about constructors before starting today's video.

3
00:00:07,900 --> 00:00:15,690
I want to cover two more things that I forgot to cover in the last review so the first thing is see

4
00:00:16,590 --> 00:00:20,260
we have public private and then again public.

5
00:00:20,250 --> 00:00:27,630
So this whole gold belongs to public discord belongs to a public so we can write we can write this code

6
00:00:27,630 --> 00:00:29,610
in a better way in a better manner.

7
00:00:29,670 --> 00:00:32,300
So how to optimize this code.

8
00:00:32,370 --> 00:00:41,350
First of all let's remove and document from here and put it in the public section and let's remove this

9
00:00:41,350 --> 00:00:46,040
line.

10
00:00:46,080 --> 00:00:49,630
So now we write public only one time.

11
00:00:49,650 --> 00:00:53,370
And similarly there is no need to write private way.

12
00:00:53,470 --> 00:00:54,510
Let me show you.

13
00:00:54,630 --> 00:00:57,590
See this age is private.

14
00:00:57,600 --> 00:00:58,860
Why.

15
00:00:58,950 --> 00:01:05,280
Because there is no access modifier defined above it so by default the access modifier is private.

16
00:01:05,340 --> 00:01:06,930
So there is no need to write private.

17
00:01:07,380 --> 00:01:11,150
And similarly in the previous code public was written two times.

18
00:01:11,190 --> 00:01:15,040
But here public is right here we write public only one time.

19
00:01:15,080 --> 00:01:15,320
Okay.

20
00:01:15,330 --> 00:01:16,590
So this code is much better.

21
00:01:16,590 --> 00:01:20,610
Earlier it was like public public and then private.

22
00:01:20,610 --> 00:01:22,110
And then again public.

23
00:01:22,170 --> 00:01:24,500
So this doesn't seem right to me.

24
00:01:24,540 --> 00:01:25,620
This one is much better.

25
00:01:25,620 --> 00:01:31,170
We are using we are using the properties what property first we are using their default property that

26
00:01:31,170 --> 00:01:32,070
default is private.

27
00:01:32,070 --> 00:01:36,110
So there is no need to write private and we are writing public on live ones.

28
00:01:36,530 --> 00:01:37,130
Okay.

29
00:01:37,140 --> 00:01:43,470
Second thing that I want to cover is how display function can access each and all no fee.

30
00:01:43,470 --> 00:01:45,000
Rule number is public.

31
00:01:45,090 --> 00:01:50,730
So rule number can be accessed anywhere in the program but ages private since age is private.

32
00:01:50,730 --> 00:01:55,540
It can only be accessed within this class and display function is defined within this class.

33
00:01:55,620 --> 00:02:01,440
So display function can access each similarly gated function can also access each because good its function

34
00:02:01,440 --> 00:02:04,070
is also defined in the student class.

35
00:02:04,140 --> 00:02:11,040
And similarly stage function can also access private variable each because this function is also defined

36
00:02:11,100 --> 00:02:12,410
within the class.

37
00:02:12,420 --> 00:02:16,940
So these are the two things that I want to look about in the last radio but I forward to color.

38
00:02:16,950 --> 00:02:17,340
Okay.

39
00:02:17,340 --> 00:02:19,910
Now let's start with I this topic.

40
00:02:20,090 --> 00:02:26,280
So till now we have learned how to create classes how to create objects of a class and how to access

41
00:02:26,280 --> 00:02:29,530
properties of the object and access modifiers.

42
00:02:29,580 --> 00:02:33,420
Let's see what our construct does and how to use them.

43
00:02:33,480 --> 00:02:39,200
So when we write student S-1 what will happen

44
00:02:42,840 --> 00:02:48,100
rule number age and we get a garbage values in these fields.

45
00:02:48,120 --> 00:02:48,660
Okay.

46
00:02:48,690 --> 00:02:51,810
So if I will do s not display

47
00:02:54,570 --> 00:02:56,210
these two will get printed.

48
00:02:56,490 --> 00:02:57,260
Fine.

49
00:02:57,300 --> 00:02:59,720
Now let's analyze this a statement.

50
00:03:00,870 --> 00:03:03,360
Let's analyze this run properly what will happen.

51
00:03:03,420 --> 00:03:08,190
So this internally in debates in this we as one art student

52
00:03:11,670 --> 00:03:17,970
internally this statement will be executed in this fashion as one art student.

53
00:03:18,480 --> 00:03:21,200
So what is the meaning of astronaut student.

54
00:03:21,270 --> 00:03:31,880
So we can see here student is a function just like display student is a function just like the display

55
00:03:32,090 --> 00:03:39,310
and S1 object is calling that function but this function name is same as last name.

56
00:03:39,650 --> 00:03:44,440
The name of other classes is student and the name of the function is also student.

57
00:03:44,480 --> 00:03:47,200
So the function name is same as last name.

58
00:03:47,210 --> 00:03:54,290
So this function is called constructor this function is called constructor.

59
00:03:54,460 --> 00:03:56,730
So what is the purpose of a constructor.

60
00:03:56,980 --> 00:03:59,450
So it will do one simple thing.

61
00:03:59,530 --> 00:04:04,580
It will initialize the data member or the properties with the garbage values.

62
00:04:04,600 --> 00:04:14,100
Okay so properties and the name of properties are data members data member okay.

63
00:04:14,270 --> 00:04:20,390
So what this constructively Lou it will initialize the data member or we can say the properties of the

64
00:04:20,390 --> 00:04:22,500
object with the garbage values.

65
00:04:22,580 --> 00:04:29,090
So that's why these two properties are initialized with the God which values because this is the work

66
00:04:29,090 --> 00:04:36,750
of dysfunction so constructor function has some special properties.

67
00:04:36,750 --> 00:04:39,860
So construct basis special function.

68
00:04:39,900 --> 00:04:49,590
Now let us write some of its properties first its name will be seen misc last name so same name as the

69
00:04:49,590 --> 00:04:52,820
name of the class second.

70
00:04:52,940 --> 00:04:55,220
This function has no return type

71
00:04:58,700 --> 00:05:02,350
third properties no input argument

72
00:05:07,370 --> 00:05:08,390
no input argument.

73
00:05:08,810 --> 00:05:15,940
So these are the properties of a constructor or we can say default constructor.

74
00:05:16,060 --> 00:05:21,410
These are some of the properties of the default constructor.

75
00:05:21,630 --> 00:05:33,020
Okay so let's analyze it a bit more so I am saying when we write student S1 this statement internally

76
00:05:33,030 --> 00:05:40,980
will be interpreted as S1 dart Student object name dart function name.

77
00:05:40,980 --> 00:05:45,120
So now the question is how we created this function.

78
00:05:45,160 --> 00:05:51,720
No we have not created this a student function in our class but this function is being called and other

79
00:05:51,720 --> 00:05:54,350
properties are initialized with their default values.

80
00:05:54,360 --> 00:05:56,280
That is the god of basic values.

81
00:05:56,460 --> 00:05:57,810
So what happened is.

82
00:05:57,840 --> 00:06:02,610
So as soon as we create a class constructor is automatically created.

83
00:06:02,670 --> 00:06:08,370
So we do not need to create it so we can use this inbuilt constructor to initialize the properties of

84
00:06:08,370 --> 00:06:09,660
our object.

85
00:06:09,690 --> 00:06:16,710
Okay so we get a default constructor as soon as we create a class we can also create constructor on

86
00:06:16,710 --> 00:06:17,630
our own.

87
00:06:17,730 --> 00:06:20,520
We will see in some time how to create our own constructor.

88
00:06:21,270 --> 00:06:25,200
Okay so now let's see how the inbuilt constructor look like.

89
00:06:25,620 --> 00:06:33,390
So I told you there are some properties first there will be no return type so empty and then the name

90
00:06:33,390 --> 00:06:36,930
of the function will be say now name of the constructor will be same ethic last name.

91
00:06:36,930 --> 00:06:38,550
So the class name is student.

92
00:06:39,180 --> 00:06:43,030
So the name of the function is student no input argument.

93
00:06:43,170 --> 00:06:50,940
And similarly it will larger than anything no return type no argument and same name as the class name.

94
00:06:51,090 --> 00:06:53,280
In fact we can remove the remote.

95
00:06:53,310 --> 00:06:53,980
Okay.

96
00:06:54,000 --> 00:06:56,220
And also this.

97
00:06:56,220 --> 00:06:56,620
Okay.

98
00:06:56,730 --> 00:07:02,740
So this is the default constructor default constructor will look like this.

99
00:07:06,380 --> 00:07:09,050
So what are the properties of default constructor.

100
00:07:09,050 --> 00:07:11,150
Same name as the class name.

101
00:07:11,150 --> 00:07:13,700
No input argument and no return type.

102
00:07:15,320 --> 00:07:21,710
So as soon as we create an object this function or we can say this construct they will be called for

103
00:07:21,710 --> 00:07:24,390
every object we create constructively record.

104
00:07:24,470 --> 00:07:26,900
So what is the purpose of a constructor.

105
00:07:26,900 --> 00:07:34,850
So the purpose of a constructor the work of a constructor is it initialized the object initialize the

106
00:07:34,850 --> 00:07:41,110
object or we can see it initialize is the property of an object but the default values with regard to

107
00:07:41,110 --> 00:07:43,400
basic values okay.

108
00:07:43,510 --> 00:07:49,660
So for every object constructor will be called only once in the lifetime of the object so then it will

109
00:07:49,660 --> 00:07:53,880
be called it will recall at the time of creation of the object.

110
00:07:54,090 --> 00:08:06,000
Okay let's see some example then you will understand it better if I write student S1 then this function

111
00:08:06,000 --> 00:08:09,320
will be called if I will right.

112
00:08:09,390 --> 00:08:16,290
Student S2 then this function will be called even if I create dynamic object.

113
00:08:16,290 --> 00:08:19,140
Student Start S3 is new student

114
00:08:22,940 --> 00:08:24,880
then this function will be called.

115
00:08:24,920 --> 00:08:32,720
So basically the constructor will be called only once in the lifetime of the object at the time of the

116
00:08:32,720 --> 00:08:33,830
creation of the object.

117
00:08:35,050 --> 00:08:38,620
Okay and how all this statement will be interpreted internally.

118
00:08:38,620 --> 00:08:42,750
So this is same as S1 not student

119
00:08:45,730 --> 00:08:49,910
and this is S2 dart student.

120
00:08:50,140 --> 00:08:56,590
So internally these statements will be interpreted like this and how will the statement will be interpreted

121
00:08:56,590 --> 00:08:57,540
internally.

122
00:08:57,620 --> 00:09:00,500
Star S3 dart.

123
00:09:00,730 --> 00:09:01,840
Function name.

124
00:09:01,900 --> 00:09:06,590
Student or we can see S3 ATL student

125
00:09:11,150 --> 00:09:13,370
Okay so now let's seeing called

126
00:09:17,250 --> 00:09:18,420
Let's Make a constructor

127
00:09:21,000 --> 00:09:22,650
let's make a default constructor

128
00:09:28,170 --> 00:09:32,000
so the function name will be same as the class name last name is student.

129
00:09:32,010 --> 00:09:34,240
So function name will also be student.

130
00:09:34,440 --> 00:09:37,660
There will be no input argument.

131
00:09:39,040 --> 00:09:40,200
And that's all.

132
00:09:40,240 --> 00:09:42,100
So this is our default constructor.

133
00:09:43,030 --> 00:09:48,780
Okay now internal constructor will look exactly like this.

134
00:09:48,790 --> 00:09:57,820
Now one important thing is as soon as we create our own constructor the internal constructor is no longer

135
00:09:57,820 --> 00:09:59,200
available to us.

136
00:09:59,290 --> 00:10:01,990
So this is the constructor that we have created

137
00:10:05,070 --> 00:10:10,500
so as soon as we create our own constructor and then construct that is no longer available to us.

138
00:10:10,500 --> 00:10:16,180
So now if we really create object then I will constructively be called internal constructor will not

139
00:10:16,220 --> 00:10:18,870
recall because it is not there.

140
00:10:18,870 --> 00:10:23,740
Okay so I would constructively do the same book as the internal construct I was doing.

141
00:10:23,940 --> 00:10:30,070
That is it will initialize every property of the object to a default value okay.

142
00:10:30,120 --> 00:10:31,370
Now let's see

143
00:10:35,250 --> 00:10:38,630
let's say some statements here a brand statement.

144
00:10:38,730 --> 00:10:39,480
So we'll see out

145
00:10:44,630 --> 00:10:45,470
Gestapo guard

146
00:10:51,410 --> 00:10:51,710
okay.

147
00:10:51,720 --> 00:10:54,780
Now let us create some object here.

148
00:10:55,150 --> 00:11:07,520
So student S1 student S1 what will happen as soon as this object is created it will call the constructor

149
00:11:07,520 --> 00:11:13,270
that we have created and Daniel construct does not do really well because we gave it our own constructed.

150
00:11:13,530 --> 00:11:18,940
Now let's call the function display word display function will do it will print that you gender number

151
00:11:19,010 --> 00:11:22,020
and since the agent that all number we have not set out oneself.

152
00:11:22,070 --> 00:11:31,340
They both contain God which values similarly let's create another object student S2 and let's call the

153
00:11:31,340 --> 00:11:36,000
display function.

154
00:11:36,280 --> 00:11:43,180
Now let's create a dynamic object so slowly start history as new student

155
00:11:51,170 --> 00:11:55,920
and let's call the display function.

156
00:11:56,030 --> 00:11:57,770
OK so what will we do.

157
00:11:58,100 --> 00:12:03,130
So if I had run this file what will be out I would put first.

158
00:12:03,170 --> 00:12:04,670
I created this object.

159
00:12:04,700 --> 00:12:07,380
So what will happen constructively recalled.

160
00:12:07,460 --> 00:12:16,370
So output will be constructor called and then display function will print the agent that will number

161
00:12:16,460 --> 00:12:17,390
both out of garbage.

162
00:12:17,420 --> 00:12:23,180
So garbage value garbage value then then the concept will be called for object as to so output will

163
00:12:23,180 --> 00:12:24,410
be constructor called

164
00:12:27,680 --> 00:12:32,050
and then it will print the garbage will lose each and the roll number both out of garbage.

165
00:12:32,060 --> 00:12:37,940
And similarly for this concept called and garbage value of each garbage value overall number.

166
00:12:37,940 --> 00:12:39,860
So this is I would expect it output.

167
00:12:39,860 --> 00:12:42,470
Now let's see where do we add output.

168
00:12:42,470 --> 00:12:45,240
So first we have to run this file.

169
00:12:45,410 --> 00:12:49,240
Now we will run this file.

170
00:12:49,290 --> 00:12:52,850
Now you can see the output concept called for object S1.

171
00:12:53,040 --> 00:12:58,380
Then the garbage values of a general lumber concept called for object as to garbage value of a general

172
00:12:58,380 --> 00:13:04,410
lumber concept called for Dynamic object as tree and the garbage values of a general number.

173
00:13:05,190 --> 00:13:05,810
Okay.

174
00:13:05,820 --> 00:13:09,250
So whenever we create objects and build constructive will be called.

175
00:13:09,540 --> 00:13:15,810
But if we create our own concept then our constructed will be called and internal constructor will vanish

176
00:13:16,010 --> 00:13:18,220
and mental construct that will go away as soon as.

177
00:13:18,240 --> 00:13:27,130
Because as soon as we create our own constructor Okay so we can create many constructors for example.

178
00:13:27,170 --> 00:13:33,180
This is our default sector let's create a bad image based constructor.

179
00:13:33,180 --> 00:13:36,000
So betterment based constructor.

180
00:13:36,100 --> 00:13:41,630
So as the name suggests this construct that we have big arguments.

181
00:13:42,220 --> 00:13:46,000
This constructor will take barometers as input.

182
00:13:46,060 --> 00:13:51,010
So function name will be seen as the class name which is the student.

183
00:13:51,340 --> 00:13:53,110
And let's say take input.

184
00:13:53,110 --> 00:14:00,600
Rule number and what it does is it will be assigned all number with a better metered

185
00:14:03,170 --> 00:14:06,130
and let's say 8 brand statement.

186
00:14:06,350 --> 00:14:08,420
So see out constructor to

187
00:14:13,240 --> 00:14:14,470
constructor to guard

188
00:14:23,270 --> 00:14:23,780
so

189
00:14:29,210 --> 00:14:30,610
so if you will create.

190
00:14:31,160 --> 00:14:36,550
So if we will create object with no parameters then this function will be called this constructively

191
00:14:36,560 --> 00:14:37,020
recall.

192
00:14:37,370 --> 00:14:43,390
And if we will create our object with one barometer then this function will be called.

193
00:14:43,550 --> 00:14:46,510
Okay let's take an example to understand it better.

194
00:14:50,760 --> 00:14:58,110
So if I will write student s for what will happen the default constructor will be called because there

195
00:14:58,110 --> 00:15:06,390
are no barometers but if I write if I pass a bad amateur student s Food a barometer then now what will

196
00:15:06,390 --> 00:15:08,670
happen bad image tries to construct it will be called

197
00:15:12,130 --> 00:15:20,530
See when I write student s for it will be interpreted as S for dot student

198
00:15:24,090 --> 00:15:29,880
and this student is the default constructor that we have defined a default constructor.

199
00:15:30,100 --> 00:15:36,480
But I want to call betterment based constructor so for betterment based constructor I have to pass one

200
00:15:36,480 --> 00:15:42,090
barometer which is when we have 2 percent in digital barometer.

201
00:15:42,120 --> 00:15:49,340
So this land will be interpreted as as for dot student and Ben.

202
00:15:49,510 --> 00:15:49,960
Okay.

203
00:15:50,040 --> 00:15:55,370
Now this time betterment tries to construct a will be called okay.

204
00:15:55,560 --> 00:16:00,370
So this is the concept of functional learning.

205
00:16:00,510 --> 00:16:05,610
We have covered function overloading earlier this is seem this is same as the concept of functional

206
00:16:05,610 --> 00:16:05,940
learning.

207
00:16:05,940 --> 00:16:11,820
We have two functions but one function doesn't take any input any barometer as input.

208
00:16:11,820 --> 00:16:14,790
And the second function take one digit argument as input.

209
00:16:14,790 --> 00:16:15,950
So these two are different

210
00:16:23,100 --> 00:16:24,750
so as for our display

211
00:16:32,830 --> 00:16:36,190
now lives in our program OK.

212
00:16:36,220 --> 00:16:40,780
So we have to run this file first and now we will run this file

213
00:16:45,490 --> 00:16:48,100
see constructor to call for object.

214
00:16:48,100 --> 00:16:54,160
As for constructor to is being adding Guard and as photo display print age and that remember so rule

215
00:16:54,160 --> 00:16:56,860
number is Ben because we set it and ages.

216
00:16:56,860 --> 00:16:58,630
I've got a visual view okay.

217
00:17:00,510 --> 00:17:02,550
Let's see you again see out

218
00:17:07,250 --> 00:17:18,170
betterment days to construct our demo.

219
00:17:18,240 --> 00:17:19,530
Now let's run this fighting

220
00:17:22,620 --> 00:17:29,460
see Batman based constructor demo constructor to call because it passed one input one integer argument

221
00:17:29,460 --> 00:17:36,720
as input and rule number is ages a garbage value at all but it's ten by ten because we set rule number

222
00:17:36,790 --> 00:17:37,620
with.

223
00:17:37,990 --> 00:17:38,250
Okay

224
00:17:41,600 --> 00:17:53,970
similarly we can create dynamic objects as well so student star S5 is new student and we have to pass

225
00:17:53,970 --> 00:18:00,370
an integer argument so 20 as faith not display

226
00:18:06,110 --> 00:18:08,560
okay sorry I say federal display

227
00:18:15,110 --> 00:18:22,360
so constructor to call the value of age as a garbage value and the value for number is 20

228
00:18:25,180 --> 00:18:25,650
so

229
00:18:29,610 --> 00:18:39,680
so for one object only one constructively regarded it will never happen that default and betterment

230
00:18:39,760 --> 00:18:45,230
based construct both are being getting called no if there is one object only one construct a little

231
00:18:45,230 --> 00:18:50,810
bit called only at the time of the creation of the object constructively recalled only at the time of

232
00:18:50,810 --> 00:18:52,610
the creation of the object.

233
00:18:52,640 --> 00:18:58,850
Okay so this is very important for every object when constructed will be called only at the time of

234
00:18:58,850 --> 00:19:01,010
the creation of the object.

235
00:19:01,010 --> 00:19:04,560
Okay so we will learn more about constructor in the next video.

236
00:19:05,120 --> 00:19:05,540
Thank you.
