aspose file tools*
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: 3177
    
  47

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: 14274
    
  21

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 8 API documentation
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  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 ;
}




}



 
 
subject: question about return?