DZone

Java Getter Setter

Why do we keep instance variables private? We don’t want other classes to depend on them. Moreover, it requires flexibility to change a variable’s type or implementation on a whim or an impulse. Why, then, do programmers automatically add getters and setters to their objects, exposing their private variables as if they were public?

Accessor Methods

Accessors (also known as getters and setters) are methods that let you read and write the value of an instance variable of an object.

Source: DZone