1
00:00:00,180 --> 00:00:08,810
So that was an important point that I wanted to actually let you know about running your Java projects.

2
00:00:08,810 --> 00:00:15,870
Another important point that I want to talk about is about get here and setters setter's So inside the

3
00:00:16,170 --> 00:00:23,220
class as you can see here we've got our Get help my friend and our settlement Fred for our sweet instance

4
00:00:23,220 --> 00:00:23,770
variable.

5
00:00:23,770 --> 00:00:24,150
OK.

6
00:00:24,180 --> 00:00:31,950
And we've got our little faith and on Saturday I'm afraid for our power instance variable and remember

7
00:00:31,950 --> 00:00:39,810
that I told you that we shouldn't allow any other classes other than this class to access our instance

8
00:00:39,810 --> 00:00:40,920
variables directly.

9
00:00:40,920 --> 00:00:41,660
OK.

10
00:00:41,790 --> 00:00:45,950
So always declare your instance variables private.

11
00:00:45,960 --> 00:00:46,390
OK.

12
00:00:46,440 --> 00:00:52,050
So always use the private access modifier for your instance variables.

13
00:00:52,050 --> 00:00:52,590
OK.

14
00:00:52,650 --> 00:01:00,210
At the start of the value creation I just need to type in here private and as you can see here now our

15
00:01:00,210 --> 00:01:03,970
power instance variable is private only to this class.

16
00:01:03,990 --> 00:01:04,540
OK.

17
00:01:04,830 --> 00:01:10,410
Is private and only diskless can use this power instance variable.

18
00:01:10,440 --> 00:01:14,460
No other classes can even refer to this variable.

19
00:01:14,520 --> 00:01:14,940
OK.

20
00:01:14,990 --> 00:01:22,020
If any other classes want to actually access the value of the power instance variable they can just

21
00:01:22,560 --> 00:01:24,230
use these getter I'm afraid.

22
00:01:24,300 --> 00:01:25,860
All these settled my fate.

23
00:01:25,860 --> 00:01:26,330
OK.

24
00:01:26,420 --> 00:01:31,030
So always declare your getters and setters public.

25
00:01:31,050 --> 00:01:31,530
OK.

26
00:01:31,650 --> 00:01:36,240
Use this public access modifier for your getters and setters.

27
00:01:36,420 --> 00:01:42,980
If you want to if you want to actually let any other classes in your project to use these two methods.

28
00:01:42,990 --> 00:01:43,720
OK.

29
00:01:43,800 --> 00:01:50,040
Or if you want to actually only allow the classes inside the package that this class is within it you

30
00:01:50,040 --> 00:01:54,460
can use the package access modifier which is the default access modifier OK.

31
00:01:54,570 --> 00:02:01,350
So for the instance variables always use these private access modifier and for the getters and setters

32
00:02:01,830 --> 00:02:04,470
always use the public access modifier.

33
00:02:04,470 --> 00:02:05,120
OK.

34
00:02:05,250 --> 00:02:12,600
In order to allow any other classes in your projects to access these getters and setters OK and if you

35
00:02:12,600 --> 00:02:20,700
want to actually allow only the classes inside the package to use these getters and setters just use

36
00:02:20,760 --> 00:02:26,400
the package access modifier OK which is the default access modifier and you don't need to actually put

37
00:02:26,490 --> 00:02:29,660
any keyboard at the start of your Meffert creation.

38
00:02:29,670 --> 00:02:30,070
OK.

39
00:02:30,090 --> 00:02:33,880
And here for example consider this search term effect.

40
00:02:33,910 --> 00:02:40,030
OK so now as you can see I chose a name for my argument.

41
00:02:40,140 --> 00:02:40,550
OK.

42
00:02:40,560 --> 00:02:43,010
As you can see the name of my argument is value.

43
00:02:43,010 --> 00:02:50,370
OK so now I want to actually show you another type of setter method with an argument that has the same

44
00:02:50,370 --> 00:02:53,800
name as this instance variable.

45
00:02:53,820 --> 00:02:57,300
So now let me actually comment out this set in my foot here.

46
00:02:57,300 --> 00:03:02,050
So I want to actually create a set in my faith for my speed instance variable.

47
00:03:02,250 --> 00:03:06,140
So the access modifier of my method is public.

48
00:03:06,690 --> 00:03:07,450
OK.

49
00:03:07,740 --> 00:03:12,100
And the return type of My method is void.

50
00:03:12,420 --> 00:03:16,010
The name of my method is set speed.

51
00:03:16,560 --> 00:03:17,210
OK.

52
00:03:17,640 --> 00:03:22,790
And then inside the apprentice's I can specify the arguments of my method.

53
00:03:22,920 --> 00:03:30,900
So the data type of my argument is int and the name of my argument this time is speed.

54
00:03:31,380 --> 00:03:32,150
OK.

55
00:03:32,430 --> 00:03:37,020
And then I need to open and close my method by using these curly braces.

56
00:03:37,020 --> 00:03:37,520
OK.

57
00:03:37,650 --> 00:03:38,750
As you can see here.

58
00:03:38,760 --> 00:03:44,770
So inside a method or even to actually refer to this speed instance variable.

59
00:03:44,850 --> 00:03:51,450
Ok so I cannot just type in here speed and then put an assignment operator here and then revert to the

60
00:03:51,450 --> 00:03:53,580
name of this argument here speed.

61
00:03:53,960 --> 00:03:55,770
Ok this is not right.

62
00:03:56,150 --> 00:03:56,720
OK.

63
00:03:56,730 --> 00:03:58,080
There is a problem here.

64
00:03:58,320 --> 00:04:04,670
Here in this line of code we are actually referring to this speed local variable two times.

65
00:04:04,740 --> 00:04:05,290
OK.

66
00:04:05,310 --> 00:04:10,640
In this line of code we are not actually referring to this instance variable at all.

67
00:04:10,800 --> 00:04:17,700
OK because we've got an local variable with the same name as our speed instance variable.

68
00:04:17,700 --> 00:04:18,250
OK.

69
00:04:18,540 --> 00:04:25,650
And here inside the Mefford we are actually referring only to this speed local variable not this instance

70
00:04:25,650 --> 00:04:26,690
variable.

71
00:04:26,730 --> 00:04:32,430
So in order to solve this problem we need to actually put the key word this here.

72
00:04:32,430 --> 00:04:38,630
So this dot speed assignment operator speed.

73
00:04:38,910 --> 00:04:43,880
So here as you can see I am referring to this speed instance variable.

74
00:04:43,910 --> 00:04:44,830
Ok so here.

75
00:04:44,850 --> 00:04:49,120
This means this keyword here means this class.

76
00:04:49,140 --> 00:04:49,880
OK.

77
00:04:50,190 --> 00:04:51,880
That's speed.

78
00:04:51,990 --> 00:04:57,620
And by using the dot notation we can actually access the instance variables of this class.

79
00:04:57,640 --> 00:05:02,490
Ok I could successfully is this split into this variable.

80
00:05:02,680 --> 00:05:05,150
And then I put an assignment operator here.

81
00:05:05,190 --> 00:05:08,320
Here actually referred to this argument.

82
00:05:08,340 --> 00:05:10,050
Ok to the name of this argument.

83
00:05:10,210 --> 00:05:10,670
OK.

84
00:05:10,750 --> 00:05:15,090
So this is another way for actually writing in your system if it's OK.

85
00:05:15,100 --> 00:05:21,460
You can actually specify a name like value for your arguments and then inside the method you can easily

86
00:05:21,460 --> 00:05:24,490
refer to the name of your instance variable.

87
00:05:24,490 --> 00:05:28,940
And then you can assign that argument to your instance variable.

88
00:05:29,200 --> 00:05:36,460
But if you want to actually use the same name as your instance variable for your argument name you need

89
00:05:36,460 --> 00:05:40,840
to actually put this key vote here and then use the documentation.

90
00:05:41,080 --> 00:05:44,290
And then you can access this instance variable.

91
00:05:44,290 --> 00:05:50,770
And after that we can actually assign this argument to your instance variable.

92
00:05:50,770 --> 00:05:55,630
Ok so this is another way for actually creating your set her Moffats.

93
00:05:55,640 --> 00:05:58,410
OK for our power instance variable.

94
00:05:58,540 --> 00:06:05,920
So here I can I try to comment out this certain method and then I can actually create a set method for

95
00:06:05,920 --> 00:06:08,230
my power instance variable.

96
00:06:08,410 --> 00:06:16,040
So the access modifier of my method is public and the return type of My method is void.

97
00:06:16,120 --> 00:06:19,460
The name of my method is said Power.

98
00:06:19,960 --> 00:06:25,720
And then inside the parenthesis I need to specify the arguments of my method.

99
00:06:25,960 --> 00:06:33,850
So if it is going to actually accept one argument so the data type of my argument is int and the name

100
00:06:33,850 --> 00:06:42,880
of my argument this time is power and then I need to open and close my method by using these curly braces.

101
00:06:42,880 --> 00:06:43,520
OK.

102
00:06:43,720 --> 00:06:48,920
So here first of all I want to actually refer to the power instance variable.

103
00:06:49,120 --> 00:06:52,530
So I need to actually put this key word here.

104
00:06:52,660 --> 00:06:55,910
These dots power.

105
00:06:56,110 --> 00:06:59,240
So here this refers to this dog class.

106
00:06:59,260 --> 00:07:00,320
OK.

107
00:07:00,490 --> 00:07:06,520
And then we use the starting rotation and then if we refer to our power instance variable as you can

108
00:07:06,520 --> 00:07:14,010
see here and then we put an assignment operator here and then we referred to the name of our argument.

109
00:07:14,020 --> 00:07:14,560
OK.

110
00:07:14,680 --> 00:07:21,060
Now I want to show you how you can create these getters and setters in another way.

111
00:07:21,280 --> 00:07:21,860
OK.

112
00:07:22,300 --> 00:07:33,810
So for example let me actually comment out this get on my feet here and let me comment out this setter

113
00:07:33,820 --> 00:07:34,700
here.

114
00:07:37,490 --> 00:07:43,120
So now I want to actually create our get here and our set here for my speed.

115
00:07:43,130 --> 00:07:44,410
Instance variable.

116
00:07:44,570 --> 00:07:45,210
Ok.

117
00:07:45,590 --> 00:07:46,490
So here.

118
00:07:46,940 --> 00:07:51,590
First of all I want to create a get out of my faith for my speed instance variable.

119
00:07:51,680 --> 00:07:54,870
So the access modifier public.

120
00:07:55,390 --> 00:07:56,080
OK.

121
00:07:56,330 --> 00:08:04,130
And the return type of my Manford is in and the name of my method is good speed

122
00:08:06,930 --> 00:08:07,890
Okay.

123
00:08:08,440 --> 00:08:12,110
And then I need to put in a pair of round brackets after my name.

124
00:08:12,310 --> 00:08:16,510
And then I need to open and close my method by using these curly braces.

125
00:08:16,510 --> 00:08:16,900
OK.

126
00:08:16,930 --> 00:08:24,040
So inside this method I want to actually get the value of this instance variable and then do some operations

127
00:08:24,250 --> 00:08:27,260
on the value of this spit instance instance value.

128
00:08:27,310 --> 00:08:30,200
And after that I want to return that value.

129
00:08:30,310 --> 00:08:32,050
So let me show you how we can do that.

130
00:08:32,140 --> 00:08:41,180
So first of all I referred to the name of my speed instance variable speed OK and then I put an assignment

131
00:08:41,210 --> 00:08:48,950
operator here and then again I refer to the name of my spit instance variable and then here I want to

132
00:08:48,950 --> 00:08:57,230
multiply the value of this instance variable by 2 and then I want to assign that value to my speed instance

133
00:08:57,230 --> 00:08:57,990
variable here.

134
00:08:58,020 --> 00:09:04,560
OK so now I want to return that value speed.

135
00:09:04,760 --> 00:09:12,680
So as you can see here this time I didn't actually return the value of this instance variable directly.

136
00:09:12,680 --> 00:09:16,050
First I did some changes to this value.

137
00:09:16,220 --> 00:09:23,840
And then I assigned that value to this instance variable and in line 11 and I returned the value of

138
00:09:23,840 --> 00:09:25,450
the speed instance variable.

139
00:09:25,580 --> 00:09:32,510
So now inside the main class here let me actually create another object from the class.

140
00:09:32,510 --> 00:09:36,410
First of all I need to refer to the name of my dog class

141
00:09:39,370 --> 00:09:40,130
OK.

142
00:09:40,560 --> 00:09:43,290
And then I need to get my object on name.

143
00:09:43,440 --> 00:09:48,950
So for example the name of my object is my fourth dog.

144
00:09:49,470 --> 00:09:50,320
OK.

145
00:09:50,730 --> 00:09:53,360
And then I put an assignment operator here.

146
00:09:53,700 --> 00:09:56,740
And then I use this keyboard here new.

147
00:09:57,060 --> 00:09:59,890
And then again I'll refer to the name of my class.

148
00:09:59,910 --> 00:10:00,490
OK.

149
00:10:00,690 --> 00:10:04,620
And then I put a pair of round brackets after my class name.

