Hi Can somebody throw more light on this, This is from JLS(page 178) ________________________________________________________________ Except for the possibility of explicit constructor invocations, the body of a constructor is like the body of a method (�8.4.5). A return statement (�14.15) may be used in the body of a constructor if it does not include an expression. _________________________________________________________________ As far i know, constructors cannot return a value. Please help, i am very cconfused. Thanx Neelkanth
JLS is correct you can have empty "return" keyword in the constructor but you cannot assign any value to that return. On the other hand if you add return type in the constructor signature, that will turn into a method with the same name as class. (another strange act of JAVA)see the following example. example: class Aclass { Aclass() {System.out.println("I am in Constructor"); return; } int Aclass() { System.out.println("I am in method"); return 4; } public static void main( String argv[] ){ Aclass a = new Aclass(); a.Aclass(); } } Output : I am in Constructor I am in method
Neelkanth K
Greenhorn
Joined: Feb 13, 2001
Posts: 4
posted
0
Thanks Wasim & Richard, Now i got it, Thanks for explanation Neelkanth