【发布时间】:2011-10-31 04:33:24
【问题描述】:
interface Test {
public void test();
}
public class TestMain {
private String h = "AAA";
public static void main(String[] args) {
TestMain t = new TestMain();
}
public TestMain() {
Test t = new Test() {
public void test() {
System.out.println( h );
}
};
t.test();
}
}
上面的源码运行良好。
但我认为匿名类应该无法访问变量“h”。 我需要知道为什么它运作良好。
提前感谢您的所有帮助!
【问题讨论】:
标签: java private inner-classes