O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Static Nested Classes

A static nested class is declared inside another class and is declared with the static modifier. Like static methods, a static nested class can only refer directly to static variables and methods. It can refer to instance variables and methods only when given a reference to an object of the enclosing class type. The following code is a rough outline of the way a static class is declared:

class NormalClass {
   // static methods and variables
   static class NestedClass {
       // methods and variables of NestedClass
     }
   // instance methods and variables of NormalClass
}

A Static Nested Class Example

Most of the examples of static nested classes we have seen have been a little forced, but we have found a more realistic (and fun) example, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required