Sometimes you need a pure class, and to be instantiated only once in your code. When this is the case, you can use an anonymous inner class. It is called an inner class because it defined inside another class.
Anonymous inner class are the local inner classes that declared without a name, but an object of this class can be created. All of the code for the anonymous class is coded within the method where we need to create an instance of the anonymous class. Since anonymous inner classes do not have a name so you cannot use the new keyword in the usual way to create an instance of the class. Anonymous inner classes are declared and instantiated at the same time.