1
00:00:00,560 --> 00:00:04,830
This type of constructor is called the default constructor OK.

2
00:00:05,360 --> 00:00:12,080
In this example we are creating the no argument constructor in the Tiger class.

3
00:00:12,170 --> 00:00:16,250
It will be invoked at the time of object creation.

4
00:00:16,500 --> 00:00:24,660
OK so as you can see here inside the main class we are creating an object for this type of class.

5
00:00:24,680 --> 00:00:30,170
So now me actually comment out these lines of code here because I want to create another and other object

6
00:00:30,170 --> 00:00:31,850
from your class.

7
00:00:31,880 --> 00:00:41,860
So first I need to refer to the name of my class and the name of my object is my second tiger.

8
00:00:42,770 --> 00:00:50,120
And then I put an assignment operator here and then I put this key word here new and then I referred

9
00:00:50,120 --> 00:00:57,130
to the name of my class name again Tiger and then I put a pair of down brackets after my classily.

10
00:00:57,270 --> 00:01:02,680
OK so now as you can see I created an object from this tiger class.

11
00:01:02,720 --> 00:01:03,260
OK.

12
00:01:03,470 --> 00:01:11,390
So now the inside of this tiger class I want to actually output some values to the console when ever

13
00:01:11,600 --> 00:01:17,240
an object from the tiger class is created inside of this tiger constructor I just need to type in system

14
00:01:17,660 --> 00:01:24,740
that out that print land and then inside the apprentice's I just need to put in two double quotes and

15
00:01:24,740 --> 00:01:27,930
then inside it all coats I just need to typing this.

16
00:01:30,260 --> 00:01:30,920
Default

17
00:01:33,680 --> 00:01:36,290
constructor OK.

18
00:01:37,010 --> 00:01:44,000
So as you can see here I created a constructor inside of my tiger class and inside of this constructor

19
00:01:44,330 --> 00:01:47,720
I decided to Outwood some values to the console.

20
00:01:47,960 --> 00:01:53,810
So inside the main class as you can see we created an object from this tiger class and the name of this

21
00:01:53,900 --> 00:01:56,060
object is my second tiger.

22
00:01:56,060 --> 00:01:56,800
OK.

23
00:01:56,990 --> 00:02:00,070
So now if I it on my project let's see what happens.

24
00:02:00,230 --> 00:02:04,020
So as you can see here this is the value that is outputted to the console.

25
00:02:04,220 --> 00:02:06,770
And this is our default constructor.

26
00:02:06,770 --> 00:02:07,450
OK.

27
00:02:07,730 --> 00:02:14,240
So inside of this main class and inside of this main method we didn't try to actually output anything

28
00:02:14,240 --> 00:02:22,100
to the console and we only actually created an object from this tile class in line 14 inside of the

29
00:02:22,100 --> 00:02:22,680
main method.

30
00:02:22,700 --> 00:02:23,200
OK.

31
00:02:23,400 --> 00:02:31,190
But inside of the target class we created our default constructor with no arguments and inside of this

32
00:02:31,190 --> 00:02:34,450
constructor I decided to output some values to the console.

33
00:02:34,450 --> 00:02:35,960
OK so this is that value.

34
00:02:36,050 --> 00:02:36,760
OK.

35
00:02:37,220 --> 00:02:41,990
And remember that we can actually create unlimited constructors in our classes.

36
00:02:42,070 --> 00:02:42,600
OK.

37
00:02:42,710 --> 00:02:50,120
So for example this is called the default constructor and I can actually create a padded motorized constructor

38
00:02:50,130 --> 00:02:56,240
OK constructor with argument list is known as padding meteoroids the constructor.

39
00:02:56,240 --> 00:03:02,450
So anality actually comments out of this constructor here and now I want to actually create a parametrized

40
00:03:02,480 --> 00:03:03,170
constructor.

41
00:03:03,220 --> 00:03:14,370
OK so here I just need to type in public OK the access modifier of my constructor is public and the

42
00:03:14,370 --> 00:03:20,760
name of my constructor must be the same as the name of the class Tiger and I need to put on a pair of

43
00:03:20,760 --> 00:03:27,060
round brackets after my constructor name and that I need to open and close my constructor by using these

44
00:03:27,060 --> 00:03:28,160
curly braces.

45
00:03:28,200 --> 00:03:34,110
So as you can see here I want to actually specify that this constructor is going to accept some values.

46
00:03:34,130 --> 00:03:37,300
OK we can actually pass values to the constructor.

47
00:03:37,440 --> 00:03:43,690
So inside of this prentices I can just typing int for example Nahm one.

48
00:03:43,800 --> 00:03:49,000
And then I can actually create another argument ain't none too ok.

49
00:03:49,320 --> 00:03:56,100
I can actually create a variable for example int result and then I can put in an assignment operator

50
00:03:56,100 --> 00:04:01,560
here refers to the name of my non-valid argument plus numb to argument.

51
00:04:01,560 --> 00:04:02,410
OK.

52
00:04:02,730 --> 00:04:07,280
And then I can output the value of the result variable to the console.

53
00:04:07,290 --> 00:04:13,520
So I just need to type in her system thought out that princeling and an inside the practices.

54
00:04:13,530 --> 00:04:18,960
I can't just refer to the name of the results variable and then I need to put in a semi-colon at the

55
00:04:18,960 --> 00:04:20,510
end of my statement.

56
00:04:20,520 --> 00:04:25,910
So now inside of the main class as you can see it's now showing us an error.

57
00:04:25,980 --> 00:04:31,540
OK so let's actually hover our mouse pointer over the error area and see what's the error.

58
00:04:31,590 --> 00:04:36,090
So as you can see here it says de-construct here Tiger is undefined.

59
00:04:36,170 --> 00:04:36,830
OK.

60
00:04:36,960 --> 00:04:43,770
So as you can see here we created a constructor inside of the tiger class that actually accepts arguments.

61
00:04:43,770 --> 00:04:44,410
OK.

62
00:04:44,670 --> 00:04:48,670
So the default constructor is not going to be called anymore.

63
00:04:49,080 --> 00:04:53,000
So we need to actually call this constructor from now on.

64
00:04:53,070 --> 00:04:53,640
OK.

65
00:04:53,850 --> 00:05:01,830
So inside of the main class if I actually delete this tiger class name here and if I just refer to the

66
00:05:01,830 --> 00:05:08,400
name of my pager class and if I actually use the autocomplete feature of the eclipse by pressing under

67
00:05:08,400 --> 00:05:15,180
control key plus the space key on my keyboard as you can see it's now recommending us to choose this

68
00:05:15,180 --> 00:05:21,390
option here Tiger and in say the prentices is not one comma in into number two.

69
00:05:21,480 --> 00:05:26,490
So if I choose this option as you can see I can actually pass some values here.

70
00:05:26,520 --> 00:05:29,110
The first value that you want to pass is number two.

71
00:05:29,190 --> 00:05:32,310
And the second value that you want to pass is number four.

72
00:05:32,640 --> 00:05:36,640
And I need to put in a semi-colon at the end of my statement.

73
00:05:36,660 --> 00:05:40,360
So now if I get on my project let's see what happens.

74
00:05:40,440 --> 00:05:43,270
As you can see this value is now outputted to the console.

75
00:05:43,380 --> 00:05:49,910
So as you can see here in line 14 I created an object from the tiger class.

76
00:05:50,120 --> 00:05:50,730
OK.

77
00:05:50,730 --> 00:05:52,410
So then my project runs.

78
00:05:52,620 --> 00:05:56,350
It's going to first actually run the codes inside of this main if.

79
00:05:56,370 --> 00:05:56,810
OK.

80
00:05:56,850 --> 00:06:03,630
And inside of this main effect I created an object from this tiger class in line 14.

81
00:06:03,630 --> 00:06:04,110
OK.

82
00:06:04,110 --> 00:06:09,900
And as you know a constructor is a block of code which is going to be run whenever you actually create

83
00:06:09,960 --> 00:06:11,070
an object.

84
00:06:11,070 --> 00:06:11,630
OK.

85
00:06:11,640 --> 00:06:17,720
So then you actually create an object from the target class it's going to actually add on our constructor.

86
00:06:17,730 --> 00:06:18,290
OK.

87
00:06:18,420 --> 00:06:19,620
Inside the Target Class.

88
00:06:19,620 --> 00:06:23,520
So as you can see here this is our constructor for our tiger class.

89
00:06:23,520 --> 00:06:24,240
OK.

90
00:06:24,570 --> 00:06:28,210
And then it's going I cheated on the codes inside of the constructor.

91
00:06:28,410 --> 00:06:36,300
So as you can see here I created a value here called result and then I decided to actually assign the

92
00:06:36,300 --> 00:06:40,710
result of this operation here to this variable and an inline 14.

93
00:06:40,740 --> 00:06:43,540
I decided to Outwood that value to the console.

94
00:06:43,560 --> 00:06:46,400
So this is that value OK number 6.

95
00:06:46,410 --> 00:06:50,190
So number two plus number four is number six.

96
00:06:50,190 --> 00:06:50,970
OK.

97
00:06:51,000 --> 00:06:57,250
So now if I actually comment out this constructor here as you can see let's see what happens inside

98
00:06:57,270 --> 00:06:57,990
the main class.

99
00:06:57,990 --> 00:06:59,610
It's now showing us an error.

100
00:06:59,610 --> 00:07:04,700
So now let's actually hover our mouse pointer over error area and see what's the error.

101
00:07:04,710 --> 00:07:05,260
OK.

102
00:07:05,310 --> 00:07:09,280
As you can see here the constructor's Tiger Prentice's it.

103
00:07:09,320 --> 00:07:11,100
It is undefined.

104
00:07:11,310 --> 00:07:11,910
OK.

105
00:07:12,030 --> 00:07:14,410
What's the problem inside the tiger class.

106
00:07:14,430 --> 00:07:20,840
We don't have any constructor which specifies that it's going to accept two arguments of type integer.

107
00:07:20,880 --> 00:07:21,330
OK.

108
00:07:21,360 --> 00:07:24,560
As you can see here we commented out this constructor here.

109
00:07:24,690 --> 00:07:27,230
So it is not going to be executed anymore.

110
00:07:27,510 --> 00:07:32,220
So we need to actually use the default constructor which has no arguments.

111
00:07:32,220 --> 00:07:34,950
As you can see here now the error is gone.

112
00:07:35,070 --> 00:07:38,120
And if I had on my project again nothing is going to happen here.

113
00:07:38,130 --> 00:07:38,520
OK.

114
00:07:38,520 --> 00:07:41,910
As you can see inside the console Nothing is here.

115
00:07:42,150 --> 00:07:42,450
OK.

116
00:07:42,450 --> 00:07:42,990
Why.

117
00:07:42,990 --> 00:07:46,920
Because you are actually creating an object from the target class as you can see here.

118
00:07:46,980 --> 00:07:50,360
We didn't create any constructor inside of the target class.

119
00:07:50,370 --> 00:07:53,380
So it's going to actually execute the default constructor OK.

120
00:07:53,400 --> 00:07:58,250
And now I want to actually show you and other important point about constructors.

121
00:07:58,260 --> 00:08:03,630
So inside the tigers of a fight as you can see here let's say that let's say that I don't want to actually

122
00:08:03,660 --> 00:08:06,360
assign any values to this instance value but ok.

123
00:08:06,800 --> 00:08:12,600
16 inside the target class I just declare it an instance variable called speed.

124
00:08:12,650 --> 00:08:16,290
I'm not assigning any values to this instance value but OK.

125
00:08:16,490 --> 00:08:19,420
So after creating this instance variable.

126
00:08:19,610 --> 00:08:23,590
Now I want to create another constructor for Tiger class.

127
00:08:23,600 --> 00:08:24,040
OK.

128
00:08:24,140 --> 00:08:28,140
So again the access modifier of this constructor is public.

129
00:08:29,390 --> 00:08:33,850
And the name of the constructor must be the same as the name of the class tiger.

130
00:08:34,000 --> 00:08:34,670
OK.

131
00:08:35,060 --> 00:08:41,300
And I need to put in a pair of and brackets after my constructor name and then I need to open and close

132
00:08:41,300 --> 00:08:43,910
my constructor by using these curly braces.

133
00:08:43,970 --> 00:08:52,610
So now I can actually refer to the name of my spit instance variable and then I can assign a value to

134
00:08:52,610 --> 00:08:54,440
this instance variable.

135
00:08:54,440 --> 00:09:00,710
Ok so now if you want to output that value to the concert I just need to type in system that out that

136
00:09:00,860 --> 00:09:01,730
insulin.

137
00:09:02,000 --> 00:09:07,910
And then inside the prentices I can just refer to the name of my speed instance variable and then I

138
00:09:07,910 --> 00:09:11,200
need to put in a semi-colon at the end of my statement.

139
00:09:11,210 --> 00:09:17,760
So now inside the main class as you can see here I created an object from the tiger class.

140
00:09:17,780 --> 00:09:18,880
OK.

141
00:09:19,250 --> 00:09:22,750
So now if I need on my project let's see what happens.

142
00:09:22,850 --> 00:09:26,630
As you can see this value is now outputted to the console.

143
00:09:26,630 --> 00:09:32,800
This value is the value of this speed instance variable that we created inside the tiger class.

144
00:09:32,810 --> 00:09:33,350
OK.

145
00:09:33,470 --> 00:09:42,320
But we created another constructor here inside the tiger class I assigned a value to this speed instance

146
00:09:42,320 --> 00:09:43,090
variable.

147
00:09:43,100 --> 00:09:48,360
So as you can see here in line 16 I just declared this instance valuable.

148
00:09:48,380 --> 00:09:54,930
But inside of this constructor I decided to actually assign a value to this spit instance variable in

149
00:09:54,940 --> 00:09:55,670
line 19.

150
00:09:55,670 --> 00:09:56,220
OK.

151
00:09:56,360 --> 00:09:57,140
As you can see here.

