New course! Every coder should learn Generative AI!
Try a free lesson+ 1
why return type is not allowed for constructor?
2 Answers
+ 2
As there is a possibility to define a method with same class name , return type is not allowed to constructor to differentiate constructor block from method block
+ 1
a constructor is use to creat an instance of your class. the return of a constructor will be an instance of your object that you wanted to creat. this special method will be only call when you will want to creat a new instance of an object.
for exemple:
String s = new String ("my New object");