Java empty block scope

Viewed 3217

I am wondering what's the purposes of using empty block. For example,

    static{
        int x = 5;
    }

    public static void main (String [] args){

          int i = 10;

          {
               int j = 0 ;
               System.out.println(x);  // compiler error : can't find x ?? why ??
               System.out.println(i);  // this is fine
          }
          System.out.println(j); //compiler error :  can't find j

    }

Can someone explains

  1. In what situation that we would want to use empty block.
  2. Are all the variables inside that empty block still goes on stack ?
  3. Why couldn't it access the static variable x ?
3 Answers
Related