Professional Documents
Culture Documents
For example
consider a situation where you need to create the instance of an object without
creating subclass of a class and also performing additional tasks such as method
overloading.
When using local inner classes, you can often go a step further. If you want to make only a
single object of this class, you dont even need to give the class a name.
Such a class is called an anonymous inner class. Usually the inner class extend some interface
or extend other class.
This syntax for anonymous classes is very cryptic.
new SuperType(construction parameters) {
inner class methods and data
}
Here, SuperType can be an interface, such
An anonymous inner class cannot have constructors because the name of a constructor
must be the same as the name of a class, and the class has no name. Instead, the
construction parameters are given to the superclass constructor. In particular,
whenever an inner class implements an interface, it cannot have any construction
parameters. Nevertheless, you must supply a set of parentheses as in