Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

unreachable statement

  Asked By: Ketan    Date: Aug 29    Category: Java    Views: 1104
  

Could anyone explain what exactly this error means:
unreachable statement

It is pointing to the if in the following statement:
if (a > b) {
^

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Arthur Cole     Answered On: Aug 29

Can u please mail the complete program I mean the cource code of the class in
which this error  is occuring.

 
Answer #2    Answered By: Jim Williamson     Answered On: Aug 29

You must be having a return statement  above that line which is not
allowed.... return statement should always be last if not in some
condition...

 
Answer #3    Answered By: Sherri Parker     Answered On: Aug 29

This is probably because that code can't be reached. Is there a 'if
(false)' before that line? Show us a few more lines before that line, I
don't think the problem is in the line itself.

 
Answer #4    Answered By: Rachel Barnes     Answered On: Aug 29

I think ur problem with the if statement  is raising
due the face that, when the control comes to the if
-else block , then it statements in either if block or
else block are bound to be executed. But in case if
you mention some return statements in those blocks
then obviously the statements after this block cannot
be executed under any circumstances. And any
unreachable code is a error  in java.
consider the following eg:

public class Test {
public static void main(String args[]){
check();
}
public static int check(){
if(true)
{
return 10; //1
}
return 20; //2
}
}

In the above code the return statement in the if block
gets executed under all situation. And the return
statement at 2 never gets opportunity to execute. So
this code is unreachable. Hence the error "UNREACHABLE
STATEMENT"

 
Answer #5    Answered By: Julio Morgan     Answered On: Aug 29

Your compiler is complaining that it can't find a way for the program
execution to ever reach that statement.

 
Answer #6    Answered By: Opal Alexander     Answered On: Aug 29

The only time I remember geting that error  is when there is a return before the
statment.
it returns before the statment. hope this helps

 
Answer #7    Answered By: Coleman Smith     Answered On: Aug 29

unreachable statement  means the statement is out of scope.. so check the braces
in the program..

if u still get the error  mail the program...

 
Didn't find what you were looking for? Find more on unreachable statement Or get search suggestion and latest updates.




Tagged: