wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question about return? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about return?" Watch "question about return?" New topic
Author

question about return?

Maxwell Wood
Ranch Hand

Joined: Feb 15, 2011
Posts: 49
hi
when is it legal to use return;
other than in a catch block
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3060
    
  38

Have you practically tried that?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

You can use a return statement to return from a method. You can use it anywhere in a method - not just in a catch block (in fact, catch blocks don't have anything in particular to do with the return statement).

Ofcourse, if your method has a return type other than void, you must specify a value to return in the return statement.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

You can use a return statement in a constructor too...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
sakthi moorthy
Ranch Hand

Joined: Oct 17, 2007
Posts: 54
Ankit Garg wrote:You can use a return statement in a constructor too...


class ReturnInConstructor {

public ReturnInConstructor() {
return ;
}




}



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about return?