So now inside the main class I just need to refer to the name of my class that speed.
OK.
As you can see I managed to successfully access this class valuable OK by just using the class itself.
And then I put the dot notation here.
And then I accessed this class variable here.
So now if I want to output the value of my class value to the console I just need to type in here system
that out that insulin and then inside the apprentice's I can just put this statement here.
OK.
And then I need to put in a semicolon at the end of my statement.
And now if I get on my project as you can see this is the value of the speed class variable.
OK.
One hundred and eighty.
OK so as you can see here are the value of this class variable is one hundred and eighty.
OK so now I want to actually create a class method.
So let me try to change this public access modifier to private OK.
And then let me actually delete this static keyword here and now I want to actually create a class method.
So after this public access modify it I just need to type in static.
And as you can see here it's going to actually show us an error here.
So let's actually hover over the error area and see what's the error cannot make a static reference
to the non-static field speed.
OK.
So as you can see here it says that our speed instance variable here is not static.
So we must actually put the static keyword here.
In order to refer to this special class variable here.
OK.
Because you actually changed this method to a class method.
OK we put this static vote after our public access modifier in order to make this method a class method.
OK.
Before that it was only an instance method.
OK but now it is a class method.
So here inside the main class.
So as you can see here it's now showing us an error.
So if I hover over the area it says the field where that speed is not visible because we actually changed
the axis modifier of this class variable to private.
So we have not referred to this class variable from outside of this class.
So I just need to delete this line of code here.
And now I want to actually see the value of that speed class variable by using that term ever.
Ok so I just need to type in here system that out that gentleman and it inside the.
I can just refer to the name of my class Bert.
OK that gets spit and then at the end of my statement I need to put in a semi-colon.
So as you can see here if I run my project as you can see this is the value of that speed class variable.
OK.
So I managed to successfully access the value of this Spaeth class variable.
OK.
So as you can see here I didn't create any object from this class.
I did actually referred to the name of this class and then I did access this my fed by just referring
to the name of this method.
OK.
And that's because of these static keyword here.
OK.
In order to make a valuable or a method a class valuable or a class method we need to put the static
keyword after our access modifier.
OK.
And here again I can actually put this static keyword here static and it inside of the main class.
I can just refer to the name of this class method.
And now I can just refer to the name of my class bird that said speed and I can actually pass a value
to this.
For example number 25.
And here as you can see I actually changed the value of this speed class variable here.
OK the value of this speed class value is 25.
And remember that I told you this earlier in this tutorial with class variables only one copy of that
value exists when the class is loaded.
Changing the value of that variable changes it for all instances of that class.
OK.
So now the value of the speed class value is 25.
And if you create any object from that birth class the value of that Spaeth class valuable is 25 not
one hundred and eighty.
OK.
So as you can see here if you want to access the value of that speed class variable and output that
value to the console.
Let's see what happens system that out that insulin and that inside the prentices I can just refer to
the name of my class bird that gets beat and then at the end of my statement I need to put in a semi-colon.
So now if you're on my project as you can see the value of that class variable and the value of the
speed class value bet is 25.
And now I want to actually create an object from this birth class.
So I just need what I can hear birds.
And the name of my object is my second bird.
And then I put an assignment operator here and I put this key vote here Neo.
And then I refer to the name of my class bird and then I put in a program and I get after my class.
And here I want to actually access the value of this speech class value add and outputs that value to
the concert.
OK.
So I just need to type in here system that out that printed then and then inside the parenthesis I can't
just refer to the name of my object.
My second bird that gets speed we can actually refer to our class benefits by using odd objects.
OK.
So now if I don't on my project as you can see the value of the speed class variable is again 25.
Why.
Because this speed valuable is actually a class variable.
OK.
And if we change the value of this variable that value is going to be changed for all of our instances
from this class.
OK.
And let me actually tell you again with class variables.
Only one copy of that variable exists when the class is loaded.
OK.
Changing the value of that variable changes it for all instances of that class.
OK so now if I actually want to change that value again I just need to type in here my second bird that
said speed for example 45.
And as you can see the value of this class variable is 45.
And if you want to output that value to the console I just need to type in here a system that out that
insulin and and inside the prentices I just need to refer to the name of my object or I can actually
refer to the name of my class because that's value it is a class variable that gets beat and I need
to put in a semicolon at the end of my statement.
And if I run my project again as you can see the value of the speed class value is 45.
OK.
And now if I want to actually create another object from my birth class I just need to type in here
word my first birth and then I put an assignment operator here.
And then I put the new word here and then I refer to the name of my class and I put in a pair of round
brackets after my class name.
So as you can see here my first birth object is now created.
So I even try to access the value of this Spaeth class variable and outputs that value to the console.
So I just need to type in here a system that's out to print to learn and then inside the apprentice's
I can just refer to the name of my object or I can refer to the name of my class.
My first object that get speed and as you can see it's going to output the value number 45 to the console.
So as you can see here this is that video.
OK.
And inside that first class I can even change the Smurfette this instance method.
So know that we call these behaviors instance Smif it's OK if we don't put the static keyboard before
the method itself.
OK.
If we put this static keyboard after this axis modifier static as a citizen if it is going to be a class
it.
OK.
So inside the main class I can't even the first of the name of my class bird does fly.
So I can't even run my project as I can see this value is output to the console.
OK so now I want to actually show you another important point about class methods in Java.
So for example inside the main class I want to create MFA.
OK.
So here I just need to type in so first that what I need to specify the access modifier of my method.
So the access modifier of mine if it is public.
OK.
And I need to specify the return type of my method.
So the return type of my method void and the name of my method is for example my fifth one.
And then I need to put in a pair of round brackets after my method name and then I need to open and
close my Meffert by using these curly braces and inside the Meffert I can put in my statements.
So I just type in here system that out that princeling line and then inside the apprentice's I can just
put it into double quotes and then inside the code I can put in my text.