The static
keyword is used to modify a member of a class. When a member is modified with static
, it can be accessed directly using the enclosing class' name, instead of using an instance of the enclosing class like you would with a non-static member.
The inner class Inner
below is a member of the class Outer
:
class Outer {
static class Inner {}
}
Therefore, Inner
can be accessed like this:
Outer.Inner
Outer
don't need to/cannot be modified by static
because it is not a member of a class. It is a class existing in the global scope. To access it, you just write its name - Outer
. It does not make sense for it to be non-static because it has no enclosing class. If it were non-static, how are you supposed to access it?