This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, An abstract from Khalid A. Mughal book for SCJP 1.4 says
Constructors cannot return a value and, hence, cannot specify a return type, not even void, in the constructor header, but they can contain the simple form of the return statement in the constructor body.
would compile and run and print Constructor. But i dont understand why would we ever need to use empty return statement in a constructor when actually it cannot return anything?
Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
As Michael wrote, you may want to quickly get out of the constructor for some reason. You would still have an instance of the object being constructed, but it would possibly be only partially initialised.
This early return technique is also useful in any method returning void. [ September 11, 2005: Message edited by: Barry Gaunt ]