RE: USING GETTER AND SETTER IN JAVA

You are viewing a single comment's thread from:

USING GETTER AND SETTER IN JAVA

in hive-109160 •  5 years ago 

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).

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!