posted 19 years ago
An inner class is a class declared within another class. For example:
An inner class is considered a member of the outer class. As a result, it can be marked with all 3 access modifiers (public, private, protected). You need an instance of the outer class in order to instantiate an instance of the inner class. For example:
OR
A warning, though, inner classes CANNOT have any static declarations, be it variables or methods. Also, remember that an inner class has access to members of the outer class. That's it for inner class.
An anonymous inner class is simply an inner class without a name. It can extend exactly onc class, or implement exactly one interface, but not both at the same time. The form is:
"Something" can be either a class or an interface. An anonymous inner class is simply either a subclass or an interface implementor that is declared without a name.
For static nested classes, it's similar to a regular inner class, except that the class itself is marked with the static modifier, like this:
A nested class can be instantiated as follows:
A nested class can have both instance and class members. It bears no relationship with the outer class.
Hope this helps.
[ February 03, 2005: Message edited by: Liang Anmian ]
Current Status:<br /> <br />SCJP 1.4<br />SCJD (in progress)