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

it2022-05-29  74

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;

转载于:https://www.cnblogs.com/plxx/p/3340084.html


最新回复(0)