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;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2021-08-09
  • 2021-07-27
  • 2021-05-29
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-08-07
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案