Quantcast
Viewing latest article 10
Browse Latest Browse All 12

Getter Setter: To Use or Not to Use

Java Getter Setter Why do we keep instance variables private? We don’t want other classes to depend on them. Moreover it gives the 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 methodsAccessors (also known as...

Viewing latest article 10
Browse Latest Browse All 12

Trending Articles