Guys what is the main function of constructors ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Guys what is the main function of constructors ?

do we use them isntead the getters and setters

4th Aug 2017, 8:44 PM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
5 Answers
+ 5
constructors are mainly for initializing attributes when the object is instantiated. Or, in layman's terms: When you create an Object Getters and Setters can be used later on after the object is already created. So, constructors aren't replacing getters and setters, since they are used together. (Constructors for when the object is made, setters for when the object is already made.)
4th Aug 2017, 9:26 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
laymans terms means saying somthing else that is easier to understand. 😊
4th Aug 2017, 10:54 PM
D_Stark
D_Stark - avatar
0
what are laymans
4th Aug 2017, 9:56 PM
Hmmam Babe khuoja
Hmmam Babe khuoja - avatar
- 1
Yea, basically we use them in place of the getters and setters, but they have a slight difference between them.
4th Aug 2017, 9:14 PM
Andrew Zhang
Andrew Zhang - avatar