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"