Hi All....... This question have been bugging me for quite a long time..wh constructors have no return type?Coz..a constructor returns a object of its Class.......so will it be right to say that a constructor have a return type "Object"???
A constructor doesn't return anything. It just provides customized initialization for the object being constructed. If you are thinking that the constructor actually constructs the object and returns it, no, it doesn't. It doesn't return anything.
This is one of those areas where you don't want to over-think it. The simple answer is: "That's the syntax of the Java language." (There are more technical reasons, as alluded to by Keith and Paul).
An advantage of constructors not having a return type is that you can easily identify when something is a constructor or a method. For example, I know, when seeing it in documentation, that public Foo() is a constructor, and public void foo() and public String bar() are methods. One may try to argue that you can tell that by the capitalization of the name (i.e. Foo() is a constructor and foo() is a method), but remember capitalization rules are conventions and not syntax rules. In other words, the compiler (or Runtime environment) cannot and do not enforce them.
Lastly, if constructors did have "return" types, aside from the technical arguments for them not having them, the syntax would simply look funny: public Foo Foo().
I think the points Paul and Keith make are getting into the technicalities of the language, especially in terms of how object referencing works. If you want the nitty gritty details of such, I am sure they or someone else can provide further details if you desire, but as I said in my opening, my recommendation is to simply not over think it.
Also notice that constructors don't get called like methods: you don't say
Foo foo = Foo();
Foo foo = new Foo();
The new operator is what actually creates (and "returns") the object, the constructor "just" initializes it. Or at least that's the way *I* interprete it...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus