At times we write methods in Java classes with local variables that we need to access even after the methods finish execution. Here's an example:
public class FinalLocalVariableTest {
public static void main(String[] args) {
final int x = 5;
Runnable r = new Runnable() {
@Override
public void run() {
System.out.println("x is " + x);
}
};
Thread t = new Thread(r);
t.start();
}
}