This content has been marked as final. Show 2 replies
Hi,Not "should not." Does not. Can not.
I have known that constructor code, that we write,
should not return any value.
But i have tried a sample code, where i have writtenNo, you didn't.
a constructor(only on the fact that it has same
method name as that of the class) which returns a
You wrote a method that has the same name as the class. It's not a constructor. If you declare a return type or void, it becomes just another method--albeit a poorly named one.
Why doesn't java mention this idea as an error, orIt's not a Constructor, just a method. And yeah, it's kind of confusing that Java lets you do that. I wish it didn't allow methods to have the same name as the class.
atleast a warning?