If the variable has access modifier "private" which restricts it from getting accessed by other class. Why set public getter methods to access it that private variable? Wouldn't it just be much better to set it to a public variable?. I'm confused. Can someone please explain this. Thank you.
Asked
Active
Viewed 18 times
0
-
if you have a `getter` you can `read` it, if you add a `setter` you can write to it, if you make it `public` you do not have this control. – Scary Wombat Feb 07 '17 at 02:55
-
@Lorenz As you are new to stackoverflow first of all see the guidelines before posting any question here – Abhishekkumar Feb 07 '17 at 02:55
-
I'm just starting to learn java. So please forgive me for asking this kind this question. – Lorenz Feb 07 '17 at 02:56
-
@Abhishekkumar, Ok thanks for letting me know. – Lorenz Feb 07 '17 at 03:00
-
Thanks @ScaryWombat. – Lorenz Feb 07 '17 at 03:00