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 ava  2s  .  c  om
    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