- 1
Why do we use getter/setter method when we can achieve the results with constructor?
Java query
2 Answers
0
a getter returns a value, a constructor returns nothing
getter/setter can be used many times, a constructor of the same object only once
getter/setter are used because in the future you can add additional functionality to act when you get/set value
also when is used only a getter and not a setter, a value can't be changed by other programmers and it is safe (is like read only)