1
00:00:00,240 --> 00:00:06,870
So here I want to for example assign another value to that speed instance variable.

2
00:00:07,040 --> 00:00:07,400
So.

3
00:00:07,430 --> 00:00:10,030
So I need to just refer to the name of my object.

4
00:00:10,050 --> 00:00:15,120
My second thought object that said Speed.

5
00:00:15,380 --> 00:00:16,090
OK.

6
00:00:16,320 --> 00:00:20,100
So here we need to actually pass our value to the Smurfette.

7
00:00:20,100 --> 00:00:22,990
For example number 24 OK.

8
00:00:23,520 --> 00:00:30,080
And here you are actually assigning another value to that speed instance variable.

9
00:00:30,240 --> 00:00:30,700
OK.

10
00:00:30,840 --> 00:00:33,150
But using this settled method.

11
00:00:33,350 --> 00:00:39,050
OK so now let me actually access that value by using q to get here my fifth.

12
00:00:39,060 --> 00:00:41,550
So if we need to actually refer to the name of an object.

13
00:00:41,550 --> 00:00:45,250
My second dog that gets Spizz.

14
00:00:45,780 --> 00:00:46,420
OK.

15
00:00:46,650 --> 00:00:49,980
And at the end of my statement I need to put in a semi-colon.

16
00:00:49,980 --> 00:00:58,350
So because this gets method returns an integer value we can actually directly output that value to the

17
00:00:58,350 --> 00:01:07,830
consulate k so we can just type in here a system that out that print to learn and that inside Apprentice's

18
00:01:08,220 --> 00:01:10,990
I can actually put this statement here.

19
00:01:11,170 --> 00:01:11,650
OK.

20
00:01:11,670 --> 00:01:16,020
My second dog that gets beat and then I can put that here.

21
00:01:16,280 --> 00:01:17,010
OK.

22
00:01:17,490 --> 00:01:22,920
So now I need to put in a semicolon at the end of my statement and if I it on my project.

23
00:01:22,930 --> 00:01:30,250
Now as you can see the value of the speed instance variable of this my second dark object is now 24.

24
00:01:30,280 --> 00:01:35,290
OK because we changed that value to 24 in line 19 OK.

25
00:01:35,340 --> 00:01:42,780
So for example if we want to actually output the value of this instance valuable before assigning this

26
00:01:42,780 --> 00:01:50,210
number 24 to the split instance variable Let's see how we can do that in this line of code.

27
00:01:50,210 --> 00:01:53,870
You are actually assigning another value to our instance variable.

28
00:01:54,030 --> 00:02:00,210
So before this line of code if you want to access the value of this instance variable i just need to

29
00:02:00,210 --> 00:02:03,980
type in system that out that insulin.

30
00:02:04,350 --> 00:02:09,730
And then inside Apprentice's I can just refer to the name of my object.

31
00:02:09,750 --> 00:02:17,320
My second dog don't get speed and then at the end of my statement I need to put in a semi-colon.

32
00:02:17,400 --> 00:02:25,740
So as you can see here R-value is 70 and in line 20 we decided to change that value to number 24 and

33
00:02:25,770 --> 00:02:30,020
in line 22 we decided to output that value to the console.

34
00:02:30,030 --> 00:02:30,480
OK.

35
00:02:30,630 --> 00:02:34,620
So disvalue here is the result of execution of this line of code here.

36
00:02:34,620 --> 00:02:35,340
OK.

37
00:02:35,400 --> 00:02:43,080
Or I can actually access the value of the power instance variable and output that value to the console

38
00:02:43,080 --> 00:02:43,640
OK.

39
00:02:43,830 --> 00:02:51,690
So I just need to type in here system got out that the print line and then inside the apprentice's I

40
00:02:51,690 --> 00:02:58,260
just need to revert to the name of my object and then I put the dot notation here and then I can access

41
00:02:58,500 --> 00:03:04,040
the value of the power instance variables by using this gets power method OK.

42
00:03:04,290 --> 00:03:09,630
And then I need to put in a semicolon at the end of my statements and if I get on my project.

43
00:03:09,660 --> 00:03:14,980
Now as you can see this is the value of the power instance variable of these.

44
00:03:15,000 --> 00:03:16,300
My second dog object.

45
00:03:16,320 --> 00:03:16,980
OK.

46
00:03:17,220 --> 00:03:25,080
Or I can actually set another value to that the power instance variable of the my second dog object.

47
00:03:25,080 --> 00:03:25,530
OK.

48
00:03:25,680 --> 00:03:34,860
So I just need to refer to the name of my object that said power and then I can actually pass another

49
00:03:34,860 --> 00:03:37,190
value to this method.

50
00:03:37,230 --> 00:03:38,800
For example number 40.

51
00:03:39,030 --> 00:03:47,800
And then I can actually again output the value of the power instance variable of this my second dog

52
00:03:47,920 --> 00:03:49,240
object to the console.

53
00:03:49,420 --> 00:03:54,250
So because this gets power my fed returns an integer value.

54
00:03:54,250 --> 00:03:56,910
I can actually assign that value to another right here.

55
00:03:57,220 --> 00:04:07,760
So I can't just type in here ain't returned value OK and that I can assign the value of the power instance

56
00:04:07,760 --> 00:04:09,410
variable to this value.

57
00:04:09,430 --> 00:04:09,810
OK.

58
00:04:09,890 --> 00:04:15,510
So I just need to refer to the name of my object that gets power.

59
00:04:15,780 --> 00:04:16,370
OK.

60
00:04:16,580 --> 00:04:19,450
And then I need to put in a semicolon at the end of my statement.

61
00:04:19,520 --> 00:04:24,530
And now I want to output the value of this variable to the console OK.

62
00:04:24,680 --> 00:04:33,380
So I just need to type in here a system that out that print line and then inside the prentices I can

63
00:04:33,380 --> 00:04:36,900
just refer to the name of my variable return value.

64
00:04:37,310 --> 00:04:40,360
And then I need to put in a semi-colon at the end of my statement.

65
00:04:40,510 --> 00:04:41,150
OK.

66
00:04:41,390 --> 00:04:49,490
And now if I get on my project as you can see this is the value of that power instance variable of this

67
00:04:49,490 --> 00:04:50,760
my second dog object.

68
00:04:50,800 --> 00:04:56,090
OK we changed that value from number 80 to number 40.

69
00:04:56,210 --> 00:04:57,000
OK.

70
00:04:57,320 --> 00:05:04,700
So as you can see here we used these setters and getters in order to access the value of our instance

71
00:05:04,720 --> 00:05:10,520
variables or we actually changed the value of those instance variables to another value.

72
00:05:10,690 --> 00:05:13,810
OK but still there is a big problem here.

73
00:05:13,990 --> 00:05:14,550
OK.

74
00:05:14,640 --> 00:05:22,280
So first of all let me point out that although we have setters and getters for our instance variables

75
00:05:22,340 --> 00:05:23,830
inside that class.

76
00:05:23,840 --> 00:05:24,340
OK.

77
00:05:24,470 --> 00:05:29,790
So this is our class and these are the setters and getters for our instance variables.

78
00:05:29,810 --> 00:05:30,710
OK.

79
00:05:31,160 --> 00:05:39,950
So although we have setters and getters for our instance variables but still I can access these instance

80
00:05:39,950 --> 00:05:42,500
variables from my main class.

81
00:05:42,500 --> 00:05:45,290
OK so now let me show you that.

82
00:05:45,410 --> 00:05:46,660
Inside the main class.

83
00:05:46,820 --> 00:05:50,580
I can easily access these instance variables directly.

84
00:05:50,600 --> 00:05:51,000
OK.

85
00:05:51,050 --> 00:05:55,620
So inside the main class let me actually comment out these lines of code here.

86
00:05:56,120 --> 00:06:01,960
And now I want to show you that still I can actually access those instance variables directly.

87
00:06:02,150 --> 00:06:06,280
So first I want to create another object from the class.

88
00:06:06,430 --> 00:06:09,990
Doug My first dog.

89
00:06:10,270 --> 00:06:10,880
Okay.

90
00:06:11,120 --> 00:06:14,110
And then I put an assignment operator here.

91
00:06:14,330 --> 00:06:16,610
And then I use this keyboard here Neal.

92
00:06:16,760 --> 00:06:23,090
And then again I refer to the name of my class and then I put a pair of round brackets after my class

93
00:06:23,090 --> 00:06:23,300
name.

94
00:06:23,300 --> 00:06:30,020
OK so now as you can see here I want to access the value of the speed instance variable and then output

95
00:06:30,080 --> 00:06:31,400
that value to the console.

96
00:06:31,580 --> 00:06:37,910
So I just need to type in here system that out but princeling and an inside Apprentice's.

97
00:06:37,940 --> 00:06:42,050
I need to refer to the name of my object that speed.

98
00:06:42,110 --> 00:06:49,820
So as you can see here I successfully managed to access this instance variable directory and this is

99
00:06:49,820 --> 00:06:51,030
not right.

100
00:06:51,200 --> 00:06:51,740
OK.

101
00:06:51,860 --> 00:06:53,850
So there is something wrong here.

102
00:06:53,870 --> 00:06:55,230
So what's the problem.

103
00:06:55,460 --> 00:07:03,530
The problem is we don't have any rules in order not to allow any other classes other than this dog class

104
00:07:03,990 --> 00:07:09,950
ok to access those instance variables directly.

105
00:07:09,950 --> 00:07:17,030
We shouldn't allow any other classes to access these instance variables directly.

106
00:07:17,030 --> 00:07:17,530
OK.

107
00:07:17,630 --> 00:07:24,950
We only want to allow any other classes other than this class to use these setters and getters that

108
00:07:25,010 --> 00:07:31,460
I provided for these instance variables in order to manipulate these instance variables.

109
00:07:31,520 --> 00:07:35,410
OK so now the question is what should we do.

110
00:07:35,480 --> 00:07:35,980
OK.

111
00:07:36,080 --> 00:07:44,420
In order not to allow any other classes other than this dog class to access these instance variables

112
00:07:44,420 --> 00:07:45,410
directly.

113
00:07:45,620 --> 00:07:50,530
And the answer is that we have to use the Java access modifiers.

114
00:07:50,720 --> 00:07:59,420
OK so what do you mean by access modifiers access modifiers are keywords in object oriented languages

115
00:07:59,660 --> 00:08:00,690
like Java.

116
00:08:00,890 --> 00:08:07,140
That set the accessibility of classes methods variables or objects.

117
00:08:07,200 --> 00:08:15,390
OK so now I'm going to show you some of those access modifiers that we use a lot in our Java programs.

118
00:08:15,390 --> 00:08:18,180
Their first access modifier is package.

119
00:08:18,210 --> 00:08:27,350
OK we have been using this access modifier in our previous projects and this means that if our variable

120
00:08:27,350 --> 00:08:35,380
for example uses the package access modifier that variable is going to be visible to the whole package.

121
00:08:35,470 --> 00:08:38,640
OK so now let me show you a real example.

122
00:08:38,660 --> 00:08:40,970
Now I want to create a variable here.

123
00:08:40,970 --> 00:08:43,500
For example inside the class.

124
00:08:43,550 --> 00:08:46,040
So int for example A.

125
00:08:46,220 --> 00:08:49,360
And then I can assign a value to a variable for example number of 32.

126
00:08:49,370 --> 00:08:53,510
So this variable uses the package access modifier.

127
00:08:53,650 --> 00:08:55,160
And you may vonder that.

128
00:08:55,180 --> 00:09:01,140
Or how did I actually identify the access modifier of this value.

129
00:09:01,220 --> 00:09:07,810
Because the package access modifier is the default access when the fire for all of our methods or variables.

130
00:09:07,850 --> 00:09:08,330
OK.

131
00:09:08,420 --> 00:09:14,330
And we don't need to actually specify that these are valuable uses the package access modifier.

132
00:09:14,440 --> 00:09:17,040
Ok by default it is package.

133
00:09:17,070 --> 00:09:23,960
OK so now as you can see here I can actually access this variable this instance variable from the main

134
00:09:24,140 --> 00:09:24,540
class.

135
00:09:24,570 --> 00:09:31,940
Ok so I can just refer to the name of my object and then I can actually access that variable and then

136
00:09:31,940 --> 00:09:34,750
I can assign another value to this variable.

137
00:09:34,820 --> 00:09:35,300
OK.

138
00:09:35,360 --> 00:09:38,680
The package means visible to the whole package.

139
00:09:38,870 --> 00:09:39,520
OK.

140
00:09:39,770 --> 00:09:48,020
So for example if I want to actually create another package in this project let's see how we can do

141
00:09:48,020 --> 00:09:48,310
that.

