A constructor must have no explicit return type.What does it means? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

A constructor must have no explicit return type.What does it means?

24th Aug 2017, 2:04 AM
Md Tauseef Kamal
Md Tauseef Kamal - avatar
4 Answers
+ 9
A constructor is used to initialise objects of your class instance, it does not have to (and cannot) return anything back to the caller.
24th Aug 2017, 2:07 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
I recommend reviewing return types in the course.
24th Aug 2017, 2:44 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
A constructor is a spacial method which is call automatically every time you create a new object, it uses for initialize objects, and it has no return value
24th Aug 2017, 7:17 AM
Shade96
Shade96 - avatar
0
In simple terms we cant use the return keyword with the constructors like public class Vehicle { private String color; Vehicle() { return color = "Red"; } } this isnt allowed with constructors. If im wrong please do correct me.Thank You In-advance
15th Jun 2022, 6:02 PM
Prithviraj Chouhan
Prithviraj Chouhan - avatar