public class Scope { public static void main(String[] args) { int outer = 1; // Exists throughout the method { // You cannot refer to a variable before its declaration. // System.out.println("inner = " + inner); // Uncomment this for an error. int inner = 2; System.out.println("inner = " + inner); // Now it's OK. System.out.println("outer = " + outer); // And outer is still here. // All variables defined in the enclosing outer block still exist, // So you cannot redefine them here. // int outer = 5; // Uncomment this for an error. } // Any variables declared in the previous inner block no longer exist. // So you cannot reference them. // System.out.println("inner = " + inner); // Uncomment this for an error. // Since inner no longer exists, you can redefine it here. int inner = 3; System.out.println("inner = " + inner); System.out.println("outer = " + outer); // And outer is still here. } }