+ 2

Getters and Setters

When would you say you need to create getters and setters. I mean.. you are doing an exercise or a little program in java, and you just notice you need them? In the examples of this mini-lesson, same thing could be done without them

2nd Mar 2017, 5:21 PM
Álvaro García Fernández
Álvaro García Fernández - avatar
2 odpowiedzi
+ 2
Methods getX() and setX() are used to interact with private variables, because you couldn't do it in other ways, since they're privates...
2nd Mar 2017, 5:35 PM
Federico Sanua
Federico Sanua - avatar
+ 1
When is a good practice to declare private variables? I know that private methods or variables are used to avoid other classes or methods can access ( read) them. But it is just programmer criteria?
9th Mar 2017, 2:10 PM
Álvaro García Fernández
Álvaro García Fernández - avatar