How do getters and setters work?

Tutorial is not really required for this. Read up on encapsulation

private String myField; //"private" means access to this is restricted to the class.

public String getMyField()
     //include validation, logic, logging or whatever you like here
    return this.myField;
public void setMyField(String value)
     //include more logic
     this.myField = value;

Leave a Comment