/** * This code is from the book: * Winder, R and Roberts, G (1998) * Developing Java Software</em> * John Wiley & Sons. * It is copyright (c) 1997 Russel Winder * and Graham Roberts. */ class l1Local1{//Class8 private String name = "l1Local1"; public void f(final String h, String w){ int j = 20; final int k = 30; class Local{ public void test(){ //OK as h is final System.out.println(h); //Cannot do this as w is not final //System.out.println(w); //Error //Cannot do this as j is not final //System.out.println(j); //Error //OK k is final System.out.println(k); //Cannot do this as i is not yet declared //System.out.println(i); //Error //Like a member class, instance variables of //the enclosing object can be accessed. //They don't need to be final. System.out.println(name); } } Local l = new Local(); l.test(); final int i = 10; } public static void main(String[] args){ l1Local1 c8 = new l1Local1(); c8.f("hello", "world"); } } /******** sample compilation & run ******* # javac l1Local1.java # java l1Local1 hello 30 l1Local1 # ******************************************/