So here I want to for example assign another value to that speed instance variable.
So.
So I need to just refer to the name of my object.
My second thought object that said Speed.
OK.
So here we need to actually pass our value to the Smurfette.
For example number 24 OK.
And here you are actually assigning another value to that speed instance variable.
OK.
But using this settled method.
OK so now let me actually access that value by using q to get here my fifth.
So if we need to actually refer to the name of an object.
My second dog that gets Spizz.
OK.
And at the end of my statement I need to put in a semi-colon.
So because this gets method returns an integer value we can actually directly output that value to the
consulate k so we can just type in here a system that out that print to learn and that inside Apprentice's
I can actually put this statement here.
OK.
My second dog that gets beat and then I can put that here.
OK.
So now I need to put in a semicolon at the end of my statement and if I it on my project.
Now as you can see the value of the speed instance variable of this my second dark object is now 24.
OK because we changed that value to 24 in line 19 OK.
So for example if we want to actually output the value of this instance valuable before assigning this
number 24 to the split instance variable Let's see how we can do that in this line of code.
You are actually assigning another value to our instance variable.
So before this line of code if you want to access the value of this instance variable i just need to
type in system that out that insulin.
And then inside Apprentice's I can just refer to the name of my object.
My second dog don't get speed and then at the end of my statement I need to put in a semi-colon.
So as you can see here R-value is 70 and in line 20 we decided to change that value to number 24 and
in line 22 we decided to output that value to the console.
OK.
So disvalue here is the result of execution of this line of code here.
OK.
Or I can actually access the value of the power instance variable and output that value to the console
OK.
So I just need to type in here system got out that the print line and then inside the apprentice's I
just need to revert to the name of my object and then I put the dot notation here and then I can access
the value of the power instance variables by using this gets power method OK.
And then I need to put in a semicolon at the end of my statements and if I get on my project.
Now as you can see this is the value of the power instance variable of these.
My second dog object.
OK.
Or I can actually set another value to that the power instance variable of the my second dog object.
OK.
So I just need to refer to the name of my object that said power and then I can actually pass another
value to this method.
For example number 40.
And then I can actually again output the value of the power instance variable of this my second dog
object to the console.
So because this gets power my fed returns an integer value.
I can actually assign that value to another right here.
So I can't just type in here ain't returned value OK and that I can assign the value of the power instance
variable to this value.
OK.
So I just need to refer to the name of my object that gets power.
OK.
And then I need to put in a semicolon at the end of my statement.
And now I want to output the value of this variable to the console OK.
So I just need to type in here a system that out that print line and then inside the prentices I can
just refer to the name of my variable return value.
And then I need to put in a semi-colon at the end of my statement.
OK.
And now if I get on my project as you can see this is the value of that power instance variable of this
my second dog object.
OK we changed that value from number 80 to number 40.
OK.
So as you can see here we used these setters and getters in order to access the value of our instance
variables or we actually changed the value of those instance variables to another value.
OK but still there is a big problem here.
OK.
So first of all let me point out that although we have setters and getters for our instance variables
inside that class.
OK.
So this is our class and these are the setters and getters for our instance variables.
OK.
So although we have setters and getters for our instance variables but still I can access these instance
variables from my main class.
OK so now let me show you that.
Inside the main class.
I can easily access these instance variables directly.
OK.
So inside the main class let me actually comment out these lines of code here.
And now I want to show you that still I can actually access those instance variables directly.
So first I want to create another object from the class.
Doug My first dog.
Okay.
And then I put an assignment operator here.
And then I use this keyboard here Neal.
And then again I refer to the name of my class and then I put a pair of round brackets after my class
name.
OK so now as you can see here I want to access the value of the speed instance variable and then output
that value to the console.
So I just need to type in here system that out but princeling and an inside Apprentice's.
I need to refer to the name of my object that speed.
So as you can see here I successfully managed to access this instance variable directory and this is
not right.
OK.
So there is something wrong here.
So what's the problem.
The problem is we don't have any rules in order not to allow any other classes other than this dog class
ok to access those instance variables directly.
We shouldn't allow any other classes to access these instance variables directly.
OK.
We only want to allow any other classes other than this class to use these setters and getters that
I provided for these instance variables in order to manipulate these instance variables.
OK so now the question is what should we do.
OK.
In order not to allow any other classes other than this dog class to access these instance variables
directly.
And the answer is that we have to use the Java access modifiers.
OK so what do you mean by access modifiers access modifiers are keywords in object oriented languages
like Java.
That set the accessibility of classes methods variables or objects.
OK so now I'm going to show you some of those access modifiers that we use a lot in our Java programs.
Their first access modifier is package.
OK we have been using this access modifier in our previous projects and this means that if our variable
for example uses the package access modifier that variable is going to be visible to the whole package.
OK so now let me show you a real example.
Now I want to create a variable here.
For example inside the class.
So int for example A.
And then I can assign a value to a variable for example number of 32.
So this variable uses the package access modifier.
And you may vonder that.
Or how did I actually identify the access modifier of this value.
Because the package access modifier is the default access when the fire for all of our methods or variables.
OK.
And we don't need to actually specify that these are valuable uses the package access modifier.
Ok by default it is package.
OK so now as you can see here I can actually access this variable this instance variable from the main
class.
Ok so I can just refer to the name of my object and then I can actually access that variable and then
I can assign another value to this variable.
OK.
The package means visible to the whole package.
OK.
So for example if I want to actually create another package in this project let's see how we can do
that.