This will compile
class X { public static void main(String args[]) { { int a = 2; } { int a = 3;
Java doesn't allow you to have two variables with the same name within scope of one another.
In your second case:
int a = 2; { // the outer 'a' is still in scope int a = 3; // so this is a redeclare <-- nooo! }
However, in your first case, each a is contained within its own scope, so all is well.
a