You are viewing a single comment's thread from:
RE: USING GETTER AND SETTER IN JAVA
So anyone can set the value from outside of the class by just using
.
. So to prevent anyone from using your variable you can use getter and setter.
This doesn't make much sense to me. There is really no difference between making a variable public and having public getters/setters, like those you have.
It's only useful if the setter actually does anything(like checking if the age
is non-negative).