Why do we use getter/setter method when we can achieve the results with constructor? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Why do we use getter/setter method when we can achieve the results with constructor?

Java query

28th Jul 2022, 6:59 AM
Nive
1 Answer
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)
28th Jul 2022, 8:33 AM
zemiak