The so-called anonymous inner class is an inner class that has no name and is usually used only once for this type of inner class.
An anonymous inner class must be declared as part of the new statement when it is created, and this will take another special form of the new statement.
Grammar:
This form of the new statement declares a novel anonymous class that expands on a given class, or implements a given interface, and also creates a new instance of that class and returns it as the result of the statement.
For example, define an interface as follows:
To define an implementation class for an interface:
The test procedure is as follows:
The result of the operation is:
Where the service is an interface, in mode two, an implementation class of the service interface is created using the anonymous inner class, and an object of the implementation class is returned.
Anonymous inner classes in Java