Question: what are getters and setters used for in java?
Answer: Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. ... The getter method returns the value of the attribute. The setter method takes a parameter and assigns it to the attribute.