Java - Access Local Variables Inside local classes

Introduction

The main() method declares two local variables called x and y.

Both variables are effectively final.

y cannot be changed because it is declared as final.

Demo

public class Main {
  public static void main(String... args) {
    int x = 100;/*from  w  w  w . j a v  a 2s.  c o  m*/
    final int y = 200;

    class LocalInner {
      void print() {
        System.out.println("x = " + x);
        System.out.println("y = " + y);
      }
    }
     //x = 100;

    LocalInner li = new LocalInner();
    li.print();
  }
}

Result