Getters and setters are the basics of Object-Oriented Programming, they allow encapsulation of class members. The reason why they are useful is because by making the field private and only allowing that field to be modified through a setter method you can make sure that no one outside of your class changes that field in a wrong way. Taking that a step further you can restrict what kind of values that variable can have. For example:
public class Dog{
private int legs;
public void setLegs(int legNum){
if(legNum > 0 & eyeNum <= 4){
legs = legNum;
}
}
public int getLegs(){
return legs;
}
}
Here we have a Dog class, this class has a private field(variable) that holds how many legs the dog has. The reason why you make it private(encapsulating it) is because you wouldn't want any other class being able to use the legs variable however it wishes. You also don't want anyone giving the dog negative legs or 300 legs for the matter. So the bottom line is that the setter and getter methods are meant to be used by other classes so that your variables don't get changed in ways that would cause bugs, otherwise you can use the variable inside of its class however you want(no need to use the gettter method inside of its own class). Hope that clears things up.