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();
}
}
Run Code Online (Sandbox Code Playgroud)
我研究过的这本书说,本地类只能使用本地类所在的final变量和方法的引用.在这个例子中,我使用的b是不是final或引用的变量.它跑了,我没有得到任何错误.怎么样?有人可以解释这种行为吗?
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |