java--局部类只能访问外包方法的final局部成员

class B523{

//    private int k = 10;

    public void go(int x, final int y){

//        int a = x+y;

        final int b = x-y;

        class InB{//局部类

            public void foo(){

                System.out.println(b);

            }

        }//InB

        InB here = new InB();

        here.foo();

    }//go

}

public class A523 {

    public static void main(String[] args) {

        new B523().go(1,2);

    }

}

//局部类只能访问外包方法的final局部变量。
//局部类的成员方法foo(),它能够访问的有外部类B的成员变量k,外包方法go()的句柄变量b和参数y,但是不能访问方法go()的局部变量a和x;

你可能感兴趣的:(final)