Question: what is getter and setter in java example?
Answer: Getters and Setters in Java Explained. 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 setter method takes a parameter and assigns it to the attribute.