A local class that is defined without a name is known as Anonymous class.
Anonymous Classes
A local class that is defined without a name is known as Anonymous class.
Anonymous classes are instantiated only once. We create a new class every time
while executing a given anonymous class definition. Anonymous classes can be
extended and can also implement an interface. In case of anonymous class, define
a class right in the middle of an expression which allows us by an inner class.
The syntax of anonymous classes is as under :
new class_name ( [ argument-list ] ) { ....... class-body ....... ....... } |
Anonymous classes can not be declared as static because they don't have a normal class declaration where it's possible to use static. They can't be define with modifiers like public, private, protected or static.