public class fun { void func() { String str = "niitn"; try { if (str.length() == 0) { System.out.print("The"); } System.exit(0); System.out.print(" Cow"); } catch (Exception e) { System.out.print(" and"); System.exit(0); } finally { System.out.print(" Chicken"); } System.out.println(" show"); } public static void main(String[]args) { fun f=new fun(); f.func(); } } In the above given code i expected an error at line number 13 because that line will never be reached.Please throw some light on it.
The statement System.exit(0); has no special meaning to the Java compiler in terms of determining whether the succeeding statements are reachable or not. To the compiler the statement is just an invocation of a class method that can be completed normally. Thus, the statement after it is reachable. If you had a 'return' statement instead, then you'd get the unreachable error but you probably already know that. J.Lacar