|
|
|
|
Next, we have (non-static) member classes. Such a class is a member of an enclosing class, but not defined as static.This is totally analogous to an instance method or instance field -- the nested class becomes an instance member of the enclosing class. Just like static member classes, such a class is enclosed within the namespace of the enclosing class, so references to it must be qualified.
Note: An instance of a member class is always associated with an instance of the
enclosing class.
Here is the main advantage of member classes:
Note that Interfaces may not be defined as non-static members. So, I'm going to take advantage of this behavior and change our Enumerator class into a member class of Stack... Note:
Stack.this Enumerator.thisStack stack = new Stack(20); Stack.Enumerator en = stack.new Enumerator() // specifies containing instance stack.super() // used when top-level class extends a // member class (esoteric)
|
|
This page was last modified on 02 October, 2007 |