Nested and Inner Classes
The functions of nested and inner classes
A private method allows a class to encapsulate operations useful only to itself. However, a method is just a method - it cannot model object oriented state and behavior. Sometimes, it makes sense to model operations that are only useful to a class as an entire object with properties and methods. A good way to encapsulate such an object within the class that uses it is to make it an inner class. Inner classes - declaration, properties, and methods - are completely contained within the main class. An inner class may be public or have no access modifier; in addition, it may even be protected or private. An anonymous inner class has no name; it is contained within a pair of curly braces within the main class. Inner classes have access to even the private variables and methods of the main class. Inner classes should only be used when appropriate. For example, a class that models a bank account holder may contain an inner class that represents his or her credit history.