This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, int i =0; is not a executable statement. It is declaration statement. if you omit the curly braces in if condition it execute the next line of the execute statement only. But here declaration statement is present. So compiler shows an error message.
if condition block has curly braces, then declaration statements and executables statements are allowed. These variables are available only in this scope. If executable statement is not present it doesn't show an error message.
Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
Because according to JLS a variable should always declare within a block
Joined: Jul 19, 2004
Hello Parameshwaran, About unreachable, it has been discusses before. Please go thru it Its quite confusing, try to understand, if not then leave it, its not going to be in SCJP exam, u dont have to worry abt these:
The bytecode from the two source samples provided by the original poster will be exactly the same. One is considered poor form; always surround statement blocks with braces, even if a statement block has only one statement. To not follow this simple, yet fundamental rule, is reasonable grounds for death by firing squad.
hai ashok, I think JLS specified that every declaration statement should be placed inside a curley braces ,otherwise it will show two errors.they are 1 .class expected. 2 not a statement. regards udhayakp