Why do we use getter/setter method when we can achieve the results with constructor? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 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 Réponse
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