Java Anonymous inner classJava anonymous inner class is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with certain "extras" such as overloading methods of a class or interface, without having to actually subclass a class. In simple words, a class that has no name is known as an anonymous inner class in Java. It should be used if you have to override a method of class or interface. Java Anonymous inner class can be created in two ways:
Java anonymous inner class example using classTestAnonymousInner.java Test it NowOutput: nice fruits Internal working of given code
Internal class generated by the compilerJava anonymous inner class example using interfaceTest it NowOutput: nice fruits Internal working of given codeIt performs two main tasks behind this code:
Internal class generated by the compilerNext TopicLocal Inner class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India