aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes return statement 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 "return statement" Watch "return statement" New topic
Author

return statement

Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
If I remove the return statement in //1 it gives compileerror saying no return statment..

Why do we need return in it ? What are the rules for using it....tofind out whether the code is error or not

import java.io.*;

public class Ppvg{
public static void main(String argv[]){
Ppvg p = new Ppvg();
p.fliton();
}
public int fliton(){
try{
FileInputStream din = new FileInputStream("Ppvg.java");
din.read();
}catch(IOException ioe){
System.out.println("flytwick");
return 99;
}finally{
System.out.println("fliton");
}
return -1;
}

}
achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
hai karthik
tell me which line exacty.u were saying "//1" , i did nt find it in your code.
Mausam M Kakkad
Ranch Hand

Joined: Oct 27, 2005
Posts: 40
Hi Karthik,

I assume it is the last "return"(at the end of the method) you are asking about.

In that case, "The method has to return something if its return type is not "void" ". and here "something" depends on what return type is.

Regards,
Mausam
Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
ho sorry

the last return type one
Amar Prasad
Greenhorn

Joined: Sep 28, 2005
Posts: 5
Hi,

you have first return i.e. return 99; in catch block. So it will execute iff there is any IOException.

So you need to write return -1; as the last statement of the method.

if there is any IOException your return 99; will be executed followed by finally block. else second return statement retrun -1; will be executed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return statement