+ 5

constructors

(1)whats the diff btw setter and constructor, (2)can getter be use along with constructor

10th Oct 2020, 3:34 PM
holyboi
holyboi - avatar
1 Resposta
+ 6
1) A constructor of the class will be called at the time of object instantiation. These are called only once per object creation. A setter is a method which can be used to set an object state. This can be called any number of times on an object. 2) Yes constructors and setter methods can coexist within a class and could be used appropriately.
10th Oct 2020, 3:47 PM
Avinesh
Avinesh - avatar