Java Reference
In-Depth Information
Such a class is called an inner class. An inner class is any class that is defined inside
another class. This arrangement signals to the reader of your program that the
RectangleMeasurer class is not interesting beyond the scope of this method.
Since an inner class inside a method is not a publicly accessible feature, you don't
need to document it as thoroughly.
An inner class is declared inside another class. Inner classes are commonly used
for tactical classes that should not be visible elsewhere in a program.
You can also define an inner class inside an enclosing class, but outside of its
methods. Then the inner class is available to all methods of the enclosing class.
S YNTAX 9.3: Inner Classes
Declared inside a method:
class OuterClassName
{
method signature
{
. . .
class InnerClassName
{
methods
fields
}
. . .
}
. . .
}
Declared inside the class:
class OuterClassName
{
methods
fields
accessSpecifier class
InnerClassName
{
methods
fields
}
. . .
}
403
404
Example
public class Tester
{
public static void main(String[] args)
{
class RectangleMeasurer implements Measurer
{
. . .
}
. . .
}
}
Search WWH ::




Custom Search