New course! Every coder should learn Generative AI!
Try a free lesson0
A constructor must have no explicit return type.What does it means?
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.
+ 3
I recommend reviewing return types in the course.
+ 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
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