The following Java code does not compile.
int a = 0; if(a == 1) { int b = 0; } if(a == 1) { b = 1; }
Why? There can be no code pa
{ } is used to define scope of variables.And here you declared :
{ }
if(a == 1) { int b = 0; }
So here scope of b will be only in { }.So you are using variable b outside { }, it is giving compilation error.
You can also refer this:
http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html