Skip to main content

Am I missing something about nested static classes?

1 reply [Last post]
Joined: 2009-01-23

In, in the section titled "Static Nested Classes":
Static nested classes are accessed using the enclosing class name:


For example, to create an object for the static nested class, use this syntax:

OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();

If OuterClass.StaticNestedClass *is* static, then how can you create a OuterClass.StaticNestedClass object?

Or does this example need reworking?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-05-06

A static nested class means you don't need an [i]instance[/i] of the outer class to use the nested class. You can still create instances of the static nested classes.

This is opposed to a non-static inner class, which you must create through an instance, e.g.

OuterClass outer = new OuterClass();
OuterClass.InnerClass inner = InnerClass();