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, ...
Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.