static修饰的变量,任何一个类的实例对象都可以访问,是共享的。而方法中声明的变量都是局部的,方法执行完后就要销毁,释放缓存空间的,这与static的本意背道而驰。所以不能在方法里建立,只能在类里建立。把语句移到方法外就可以了,程序如下。- public class InterfacetTest {
- interface A
- {
- }
- static class B implements A
- {static final int i = 10;
- class C implements A
- {
-
- }
- public void show()
- {
- class D implements A
- {
- public void seeOut()
- {
- int a = i;
- }
- }
- }
- }
- public class Test
- {
- public void main(String[] args)
- {
- new B();
- }
- }
- }
复制代码 |