The first code sample you provided is Dead Code and it will not compile at all ! The second code sample does compile but a warning is issued by your IDE . This is the major difference . Apart from that , the reason why the code in the second code compiles is that you are using varibales and the java compiler 'thinks' that maybe these variables will change on runtime. However, when you use the same code and replace variables with actual values , the compiler knows already at compile time that this code will not be reached ever.
Another thing I would like to point out is that if you mark your variables as final in the second code sample, you will again get compile time error ( instead of warning ) because of the "final" nature of the variable.
Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
veena - as saif's reply refers to you using variables in the second code sample, when in fact there aren't any, I'm assuming you have edited the code. Please don't do this - it makes the rest of the thread meaningless.
Joined: May 16, 2011
thanks for the reply, i had made editing mistake in the code so i have edited the code, based on that you answer,please.
the 1st sample code compiles n run successfully. No doubt. statement after else not considered as not reachable code, where as in while loop, it is.