Do constructors return a value? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Do constructors return a value?

28th Oct 2017, 4:47 PM
CoderAss
CoderAss - avatar
3 Answers
+ 16
They always return an instance of the class ;) You can't change this behavior, so constructors don't need a return type.
28th Oct 2017, 5:36 PM
Tashi N
Tashi N - avatar
+ 7
No, they don't. Not even void. After all, you cannot get anything of value from creation of an object. And void would make it more like a function.
28th Oct 2017, 4:51 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
ya constructor don't have any return type
28th Oct 2017, 5:16 PM
Nanda Balakrishnan