I understand that a block defines a scope of a variable. And empty blocks inside a method are for setting scope. But why are empty blocks inside methods initialising variables as well unlike in blocks used with loops etc.
class A{
public static void main(String args[]){
int a;
int b:
{
a = 10;
}
for(int i = 0; i < 1; i++){
b = 20;
}
System.out.println(b); //error here
System.out.println(a);
// doesnt give error and prints 10. why?
}
}
My question is : why are properties of an empty block inside a method not similar to blocks used with loops or conditional blocks etc