[英]Inner Local Classes in Java
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
变量和该本地类所在方法的引用。在此示例中,我使用了不是final
或引用的变量b
。 它运行了,我没有得到任何错误。 怎么样? 有人可以解释这种行为吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.