public class Main {
public static void main(String[] args) {
int b=1;
final int c=2;
String s1[] = new String[]{"A","B","C"};
class InnerMain{
int a=5;
public void show(){
System.out.println(s1[0]);
System.out.println("A:" + a);
System.out.println("B:" + b);
System.out.println("C:" + c);
}
}
InnerMain test =new InnerMain();
test.show();
}
}
我研究过的书说,本地类只能使用final
本地类所在的方法的变量和引用。在这个例子中,我使用b
了不是final
或引用的变量。它运行了,我没有收到任何错误。如何?有人可以解释这种行为吗?