【发布时间】:2015-02-08 23:12:58
【问题描述】:
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 或引用。它运行了,我没有收到任何错误。如何?有人可以解释这种行为吗?
【问题讨论】:
标签: java local-class