If I can set an attribute on instantiation of the class by means of a Constructor, why then do I need a Setter? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

If I can set an attribute on instantiation of the class by means of a Constructor, why then do I need a Setter?

Setters vs Constructors

1st Sep 2016, 4:01 PM
Promise Emmanuel
Promise Emmanuel - avatar
3 Réponses
+ 1
So what then are Setters really good for?
1st Sep 2016, 5:51 PM
Promise Emmanuel
Promise Emmanuel - avatar
0
you can get it by getter, there is no need of setter when you are using constructor. try yourself
1st Sep 2016, 4:52 PM
Md. Al-Mustanjid
Md. Al-Mustanjid - avatar
0
For Encapsulation
16th Dec 2017, 4:38 PM
Md. Al-Mustanjid
Md. Al-Mustanjid - avatar