The Java Tutorial says that since an inner class is associated with an instance of the enclosing class, it (the inner class) cannot define any static members itself.
It\
An inner class
may not declare static
fields unless they are compile-time constants. Hence, if you declare the static
field as final
it will work.
class Foo {
class Test {
final static int i = 10;
}
}
will compile and run perfectly
static
fields can only be declared in static
or top-level types. Hence, a (pure) static
variable can be declared only in a static
class
.