So that was an important point that I wanted to actually let you know about running your Java projects.
Another important point that I want to talk about is about get here and setters setter's So inside the
class as you can see here we've got our Get help my friend and our settlement Fred for our sweet instance
variable.
OK.
And we've got our little faith and on Saturday I'm afraid for our power instance variable and remember
that I told you that we shouldn't allow any other classes other than this class to access our instance
variables directly.
OK.
So always declare your instance variables private.
OK.
So always use the private access modifier for your instance variables.
OK.
At the start of the value creation I just need to type in here private and as you can see here now our
power instance variable is private only to this class.
OK.
Is private and only diskless can use this power instance variable.
No other classes can even refer to this variable.
OK.
If any other classes want to actually access the value of the power instance variable they can just
use these getter I'm afraid.
All these settled my fate.
OK.
So always declare your getters and setters public.
OK.
Use this public access modifier for your getters and setters.
If you want to if you want to actually let any other classes in your project to use these two methods.
OK.
Or if you want to actually only allow the classes inside the package that this class is within it you
can use the package access modifier which is the default access modifier OK.
So for the instance variables always use these private access modifier and for the getters and setters
always use the public access modifier.
OK.
In order to allow any other classes in your projects to access these getters and setters OK and if you
want to actually allow only the classes inside the package to use these getters and setters just use
the package access modifier OK which is the default access modifier and you don't need to actually put
any keyboard at the start of your Meffert creation.
OK.
And here for example consider this search term effect.
OK so now as you can see I chose a name for my argument.
OK.
As you can see the name of my argument is value.
OK so now I want to actually show you another type of setter method with an argument that has the same
name as this instance variable.
So now let me actually comment out this set in my foot here.
So I want to actually create a set in my faith for my speed instance variable.
So the access modifier of my method is public.
OK.
And the return type of My method is void.
The name of my method is set speed.
OK.
And then inside the apprentice's I can specify the arguments of my method.
So the data type of my argument is int and the name of my argument this time is speed.
OK.
And then I need to open and close my method by using these curly braces.
OK.
As you can see here.
So inside a method or even to actually refer to this speed instance variable.
Ok so I cannot just type in here speed and then put an assignment operator here and then revert to the
name of this argument here speed.
Ok this is not right.
OK.
There is a problem here.
Here in this line of code we are actually referring to this speed local variable two times.
OK.
In this line of code we are not actually referring to this instance variable at all.
OK because we've got an local variable with the same name as our speed instance variable.
OK.
And here inside the Mefford we are actually referring only to this speed local variable not this instance
variable.
So in order to solve this problem we need to actually put the key word this here.
So this dot speed assignment operator speed.
So here as you can see I am referring to this speed instance variable.
Ok so here.
This means this keyword here means this class.
OK.
That's speed.
And by using the dot notation we can actually access the instance variables of this class.
Ok I could successfully is this split into this variable.
And then I put an assignment operator here.
Here actually referred to this argument.
Ok to the name of this argument.
OK.
So this is another way for actually writing in your system if it's OK.
You can actually specify a name like value for your arguments and then inside the method you can easily
refer to the name of your instance variable.
And then you can assign that argument to your instance variable.
But if you want to actually use the same name as your instance variable for your argument name you need
to actually put this key vote here and then use the documentation.
And then you can access this instance variable.
And after that we can actually assign this argument to your instance variable.
Ok so this is another way for actually creating your set her Moffats.
OK for our power instance variable.
So here I can I try to comment out this certain method and then I can actually create a set method for
my power instance variable.
So the access modifier of my method is public and the return type of My method is void.
The name of my method is said Power.
And then inside the parenthesis I need to specify the arguments of my method.
So if it is going to actually accept one argument so the data type of my argument is int and the name
of my argument this time is power and then I need to open and close my method by using these curly braces.
OK.
So here first of all I want to actually refer to the power instance variable.
So I need to actually put this key word here.
These dots power.
So here this refers to this dog class.
OK.
And then we use the starting rotation and then if we refer to our power instance variable as you can
see here and then we put an assignment operator here and then we referred to the name of our argument.
OK.
Now I want to show you how you can create these getters and setters in another way.
OK.
So for example let me actually comment out this get on my feet here and let me comment out this setter
here.
So now I want to actually create our get here and our set here for my speed.
Instance variable.
Ok.
So here.
First of all I want to create a get out of my faith for my speed instance variable.
So the access modifier public.
OK.
And the return type of my Manford is in and the name of my method is good speed
Okay.
And then I need to put in a pair of round brackets after my name.
And then I need to open and close my method by using these curly braces.
OK.
So inside this method I want to actually get the value of this instance variable and then do some operations
on the value of this spit instance instance value.
And after that I want to return that value.
So let me show you how we can do that.
So first of all I referred to the name of my speed instance variable speed OK and then I put an assignment
operator here and then again I refer to the name of my spit instance variable and then here I want to
multiply the value of this instance variable by 2 and then I want to assign that value to my speed instance
variable here.
OK so now I want to return that value speed.
So as you can see here this time I didn't actually return the value of this instance variable directly.
First I did some changes to this value.
And then I assigned that value to this instance variable and in line 11 and I returned the value of
the speed instance variable.
So now inside the main class here let me actually create another object from the class.
First of all I need to refer to the name of my dog class
OK.
And then I need to get my object on name.
So for example the name of my object is my fourth dog.
OK.
And then I put an assignment operator here.
And then I use this keyboard here new.
And then again I'll refer to the name of my class.
OK.
And then I put a pair of round brackets after my class name.