Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ketan Dave   on Aug 29 In Java Category.

  
Question Answered By: Rachel Barnes   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"

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

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


Tagged: