1
00:00:00,420 --> 00:00:07,350
So now if I actually want to output the value of this instance variable to the console Let's see what

2
00:00:07,350 --> 00:00:11,510
happens system that out that princeling.

3
00:00:12,660 --> 00:00:18,780
And then inside the prentices I defended the name of my object that speaks OK and then I put a semicolon

4
00:00:18,840 --> 00:00:20,680
at the end of my statement.

5
00:00:20,700 --> 00:00:27,390
So now if I run on my project as you can see this is the value of this instance variables of this might

6
00:00:27,600 --> 00:00:28,050
object.

7
00:00:28,050 --> 00:00:30,480
OK first the value was 70.

8
00:00:30,660 --> 00:00:35,540
And then in line 11 we decided to change that value to number 25.

9
00:00:35,670 --> 00:00:40,440
And then in line 12 we decided to out food that's value to the consumer.

10
00:00:40,440 --> 00:00:41,730
So this is our value.

11
00:00:41,790 --> 00:00:42,340
OK.

12
00:00:42,570 --> 00:00:48,500
But this is not the proper way in order to assign a value to our instance variables.

13
00:00:48,540 --> 00:00:50,020
And this is not good.

14
00:00:50,120 --> 00:00:50,630
OK.

15
00:00:50,700 --> 00:00:57,970
We should actually use a method called setter in order to actually assign values to our instance variables.

16
00:00:58,170 --> 00:01:01,160
OK in that way our codes are more secure.

17
00:01:01,340 --> 00:01:04,650
OK so now let me show you how you can do that.

18
00:01:04,650 --> 00:01:08,870
So inside that class we need to create some if it's OK.

19
00:01:08,880 --> 00:01:15,900
So first of all I want to create a get out of my fit and a set in my head for my speed instance variable.

20
00:01:15,920 --> 00:01:16,370
OK.

21
00:01:16,470 --> 00:01:24,090
After creating our spit instance variable i just need to type pain into the return type of My method

22
00:01:24,120 --> 00:01:29,410
is it and the name of my method is get speed.

23
00:01:29,720 --> 00:01:30,370
OK.

24
00:01:30,600 --> 00:01:34,100
And then I put a pair of round brackets after my Meffert name.

25
00:01:34,350 --> 00:01:38,700
And then I open and close my method by using these curly braces.

26
00:01:38,700 --> 00:01:39,380
OK.

27
00:01:39,720 --> 00:01:46,470
So inside this method I can actually return the value of this speed instance variable.

28
00:01:46,470 --> 00:01:46,980
OK.

29
00:01:47,070 --> 00:01:50,860
So I just need to type in here return speed.

30
00:01:51,230 --> 00:01:52,030
OK.

31
00:01:52,140 --> 00:01:56,770
So as you can see here this is our getter method for this instance variable.

32
00:01:57,120 --> 00:01:59,810
The return type of this method is it.

33
00:01:59,850 --> 00:02:01,040
OK.

34
00:02:01,380 --> 00:02:04,910
And the name of this method is get speed.

35
00:02:05,170 --> 00:02:06,170
OK.

36
00:02:06,330 --> 00:02:08,670
And this left has no arguments.

37
00:02:08,880 --> 00:02:09,640
OK.

38
00:02:10,020 --> 00:02:19,060
And inside the Smurfette I am actually returning the value of this speed instance variable return speed.

39
00:02:19,420 --> 00:02:19,930
OK.

40
00:02:19,950 --> 00:02:23,660
And then I can actually create another Meffert which is the setter.

41
00:02:23,730 --> 00:02:24,320
OK.

42
00:02:24,450 --> 00:02:29,940
So here I can just type in void the return type of my Mefford is void.

43
00:02:29,970 --> 00:02:31,880
This never is going to return nothing.

44
00:02:32,040 --> 00:02:32,700
OK.

45
00:02:32,970 --> 00:02:38,080
And the name of this method is set speed.

46
00:02:38,660 --> 00:02:39,480
OK.

47
00:02:39,920 --> 00:02:45,650
And then inside Apprentice's all you want to specify that this method is going to actually accept an

48
00:02:45,710 --> 00:02:46,490
argument.

49
00:02:46,520 --> 00:02:55,340
OK so the data type of my argument is int OK and the name of my argument is for example value and then

50
00:02:55,380 --> 00:03:03,360
I open and close my Meffert by using these curly braces and inside the Smurfette I can actually refer

51
00:03:03,360 --> 00:03:06,600
to the name of my speed instance variable.

52
00:03:07,240 --> 00:03:08,010
OK.

53
00:03:08,330 --> 00:03:11,680
And then I put an assignment operator here.

54
00:03:12,020 --> 00:03:16,300
And then I refer to the value variable here.

55
00:03:16,340 --> 00:03:16,970
OK.

56
00:03:17,210 --> 00:03:21,440
So as you can see here I created or get hurt my fat.

57
00:03:21,830 --> 00:03:23,140
OK this is our Gitomer for.

58
00:03:23,150 --> 00:03:23,850
OK.

59
00:03:24,050 --> 00:03:30,050
I created a get her my friend and set her Mefford for our speed instance variable.

60
00:03:30,050 --> 00:03:30,860
OK.

61
00:03:31,370 --> 00:03:36,490
So these two methods are get here and so term effects of our speed instance variable.

62
00:03:36,500 --> 00:03:36,970
OK.

63
00:03:37,070 --> 00:03:42,800
So this get home if it is going to have a return value of type it.

64
00:03:42,950 --> 00:03:43,400
OK.

65
00:03:43,400 --> 00:03:48,500
And as you can see here I specified that the return type of this get and if it is it.

66
00:03:48,560 --> 00:03:54,250
And inside the Smurfette I returned the value of this instance variable.

67
00:03:54,350 --> 00:03:59,780
I actually created this variable and this variable inside the class.

68
00:03:59,780 --> 00:04:00,250
OK.

69
00:04:00,380 --> 00:04:09,840
So because I actually created these variables inside this class and not inside any of these methods.

70
00:04:10,160 --> 00:04:14,250
OK I can access these variables from any place in my class.

71
00:04:14,280 --> 00:04:21,890
OK but if I for example create a variable inside these settlements for example I can actually create

72
00:04:21,890 --> 00:04:28,900
a variable in a custom variable for example.

73
00:04:28,970 --> 00:04:34,760
This is of value but I cannot access this variable from this method.

74
00:04:34,790 --> 00:04:38,060
OK custom variable.

75
00:04:38,300 --> 00:04:43,390
And if I for example want to assign another value to this variable I cannot do that.

76
00:04:43,400 --> 00:04:44,000
Why.

77
00:04:44,060 --> 00:04:47,530
Because this variable is created inside the Smurfette.

78
00:04:47,540 --> 00:04:48,050
OK.

79
00:04:48,200 --> 00:04:52,330
And we cannot actually refer to this valuable insight.

80
00:04:52,340 --> 00:04:56,410
This run of it these kinds of variables are local variables.

81
00:04:56,450 --> 00:05:02,010
OK this argument here is also of local variable.

82
00:05:02,110 --> 00:05:02,520
OK.

83
00:05:02,540 --> 00:05:07,060
Because we can only refer to these variables inside this method.

84
00:05:07,130 --> 00:05:07,720
OK.

85
00:05:07,880 --> 00:05:11,220
We cannot actually refer to these variables inside a.m.-I.

86
00:05:11,260 --> 00:05:13,300
Ok for example this run method.

87
00:05:13,600 --> 00:05:14,090
OK.

88
00:05:14,180 --> 00:05:21,470
But we can actually access this split instance variable and and this power instance variable from any

89
00:05:21,480 --> 00:05:23,280
places inside our class.

90
00:05:23,360 --> 00:05:24,150
OK.

91
00:05:24,590 --> 00:05:30,710
So as you can see here I can actually access the value of the power instance variable inside the sleep

92
00:05:30,860 --> 00:05:31,340
method.

93
00:05:31,430 --> 00:05:37,670
Ok so I can just refer to the name of my power instance variable and then I can assign another value

94
00:05:37,670 --> 00:05:39,160
to this variable.

95
00:05:39,440 --> 00:05:41,920
So as you can see here we are allowed to do that.

96
00:05:41,930 --> 00:05:42,460
OK.

97
00:05:42,620 --> 00:05:49,130
But here we cannot access this variable that is created inside this set speed method.

98
00:05:49,130 --> 00:05:49,790
OK.

99
00:05:50,030 --> 00:05:54,690
So these kinds of variables are local variables because they are local.

100
00:05:54,740 --> 00:05:55,470
OK.

101
00:05:55,730 --> 00:05:58,490
So hopefully that makes sense.

102
00:05:58,490 --> 00:06:05,090
So now let me actually delete these lines of code here because I want to actually explain the concept

103
00:06:05,090 --> 00:06:06,340
of local variables.

104
00:06:06,380 --> 00:06:06,800
OK.

105
00:06:06,800 --> 00:06:09,540
And as you can see here this is our set friend.

106
00:06:09,550 --> 00:06:09,900
OK.

107
00:06:09,920 --> 00:06:16,100
The return type of this method is void and the name of this method is set speed and this Clifford accepts

108
00:06:16,190 --> 00:06:16,960
an argument.

109
00:06:16,970 --> 00:06:17,620
OK.

110
00:06:17,750 --> 00:06:23,180
And then inside this method we are actually assigning this argument to our sweet instance variable.

111
00:06:23,210 --> 00:06:23,710
OK.

112
00:06:23,840 --> 00:06:31,400
So whenever that we actually call this term effect in our code we need to actually pass our value to

113
00:06:31,400 --> 00:06:31,890
the Smurfette.

114
00:06:31,910 --> 00:06:32,570
OK.

115
00:06:32,870 --> 00:06:40,160
And that insight is nymphet we are actually assigning the past value to our speed instance variable.

116
00:06:40,160 --> 00:06:47,200
Ok so now I want to actually create a set here and I get home I friend for our power instance variable.

117
00:06:47,280 --> 00:06:51,280
So first I'm going to actually create or get hurt my friend.

118
00:06:51,290 --> 00:07:00,530
So the return type of My method is in the name of my method is get power ok and I put a pair of round

119
00:07:00,530 --> 00:07:08,720
brackets after my Meffert name and then I open and close my head by using an opening curly brace followed

120
00:07:08,720 --> 00:07:10,250
by our closing curly brace.

121
00:07:11,070 --> 00:07:11,920
OK.

122
00:07:12,330 --> 00:07:17,830
And then inside this my faith I need to return the value of the power instance variable.

123
00:07:18,000 --> 00:07:21,840
So I just need to type in return power.

124
00:07:22,290 --> 00:07:22,860
OK.

125
00:07:22,860 --> 00:07:27,830
And then let me actually create a set for my faith for our power instance variable.

126
00:07:27,840 --> 00:07:36,180
So the return type of Our method is Voyt and the name of our Meffert is set power.

127
00:07:36,790 --> 00:07:37,490
OK.

128
00:07:37,530 --> 00:07:42,920
And then I put in a pair of round brackets here after my name.

129
00:07:43,110 --> 00:07:48,210
And then I want to specify that this method is going to actually accept arguments.

130
00:07:48,240 --> 00:07:54,890
OK so the data type of my argument is int and the name of my argument is value.

131
00:07:55,220 --> 00:07:55,950
OK.

132
00:07:56,280 --> 00:08:02,070
And then I need to open and close my method by using an opening curly brace followed by our closing

133
00:08:02,080 --> 00:08:02,550
Colibri.

134
00:08:02,590 --> 00:08:03,390
OK.

135
00:08:03,780 --> 00:08:10,610
So inside this method first I need to look first to the name of my power variable power.

136
00:08:10,970 --> 00:08:11,840
OK.

137
00:08:12,210 --> 00:08:19,600
And then I put in an assignment operator here and then I referred to the name of my argument value.

138
00:08:19,730 --> 00:08:20,310
OK.

139
00:08:20,430 --> 00:08:27,150
So whenever that we actually call this Smurfette we need to actually pass our value to the Smurfette

140
00:08:27,480 --> 00:08:31,700
and then that value is going to be assigned to this power instance variable.

141
00:08:31,920 --> 00:08:39,360
Ok so in this way we can actually set values to our power instance variable.

142
00:08:39,480 --> 00:08:45,120
So you may wonder is that how we can actually use these setters and getters methods.

143
00:08:45,180 --> 00:08:48,180
So inside the main class as you can see here.

144
00:08:48,180 --> 00:08:53,730
First let me actually comment out these lines of code here and then we going to create another object

145
00:08:54,030 --> 00:08:55,130
from the start class.

146
00:08:55,140 --> 00:08:56,250
OK.

147
00:08:56,340 --> 00:09:04,250
So first I need to refer to the name of my class stock and then I need to give my object a name.

148
00:09:04,260 --> 00:09:07,720
My second dog.

149
00:09:08,440 --> 00:09:09,290
OK.

150
00:09:09,750 --> 00:09:15,580
And then I put in an assignment operator here and then I use this keyboard here knew.

151
00:09:15,960 --> 00:09:19,720
And then again I referred to the name of the class dog.

152
00:09:20,880 --> 00:09:24,490
And then I put in our programs brackets after my class name.

153
00:09:24,490 --> 00:09:25,050
OK.

154
00:09:25,260 --> 00:09:29,770
So I need to put in a semicolon at the end of my statement.

155
00:09:29,850 --> 00:09:35,230
So as you can see here we created another object from this class.

156
00:09:35,250 --> 00:09:35,650
OK.

157
00:09:35,670 --> 00:09:41,530
So here I want to actually access the value of the instance variables of my second dog object.

158
00:09:41,550 --> 00:09:42,100
OK.

159
00:09:42,270 --> 00:09:46,830
So in the past we actually accessed those instance variables directly.

160
00:09:46,830 --> 00:09:47,060
OK.

161
00:09:47,070 --> 00:09:53,550
As you can see here but here are you want to actually access the value of these instance variables by

162
00:09:53,550 --> 00:09:56,710
using these getters and setters methods.

163
00:09:56,730 --> 00:09:57,120
OK.

