Hello, in this programming video, we are going to look at the disk keyword. And we're going to be Continuing with our example from the previous part of this series. Okay, so what is the keyword. So this keyword allows you to use properties of the class within the class. And this is great if you have duplicate names. So let me give you an example.
If I create a new method, and Okay, let's create a method that allows you to actually set the health. So if I were to do probably bullied, set how, like so. And this is useful if, for example, while you're there, and we'll probably get areas in here somewhere, so we're just you know, common ground. So these are So this will be called a get I mean a setter and a getter will be something like public void wouldn't be void you'll be float the data type of the variable get health and in here we will just return like so my thinking why would we do it this way we get in the setup and instead of going the public route, if you have the public you know keyword instead of the private keyword, we're going to be covering all of this Don't worry in a separate video as well.
So actually, I'll leave that for that little video but for now, let's just make this private. So how to set the health and obviously we need to provide in the health value and let's say out how people and ignore the warning or not the one in the vote if you can get by To do e free, a free dot, that's how that's supposed to help 49. And then the last print line should be to do with health should be 49. So if I do you free, get out? No, no simply like, we get 100 they might be thinking, but we set their house to 49. And if we go back to our class, that's what this one in the boat so it says this assignment to variable how has no effect.
So in Eclipse, it actually has really useful warnings. Not only does it you know, help, you know inform you what the actual problem instead of giving you some generic method that means nothing. It actually provides, you know, alternative to help fix it. So, let's try one of these. So, he's actually put this there so This is what we're actually going to do. So remember, with a assignment, whatever is on the right, so if I say x, y, obviously these don't exist, but that doesn't matter.
This means that y is assigned to x and x now equals y. So what we want is to assign the value that's passed in to this health value, this keyword. So if we do this dot, refers to anything that's part of this class of the house, then we got live, you got to get out to any method, any variable, anything like that. So this is apply this power value that's passed in to the house variable of the class. If I rename this to, let's say, you know, w h, this will give an error Now, obviously, it's a different name. And that's it.
That's what this keyword is allows you to access properties so variable methods within the class. That's, you know, all part of that class, my thinking, why would I just go down the route of this? They call it the southern of how to, for example, or the seven on the line? Yeah, we can do that. It's just instead of, you know, constantly naming stuff, and then you know, you're looking at you thinking differently. This way you can look at anything.
Okay, this is part of the property, this house has been passed in. So that way, it's an easy way of keeping the naming simple, but just being able to identify where the value is coming from. So that's it for this keyword. If you have any questions because you can get a bit confusing, feel free to reach out. All of the source code will be available via the GitHub link, and I look forward to seeing you in the next awesome Java video.