What is use of Anonymous classes? Any real world reference will be helpful. | SoloLearn: Learn to code for FREE!

+3

What is use of Anonymous classes? Any real world reference will be helpful.

5/25/2020 5:19:11 PM

Sudarshan Phalke

3 Answers

New Answer

+3

Anonymous classes are useful when you need to override certain behaviors of a class instance without creating a new or a subclass. They let you make changes on the go. The below code is a basic demonstration on how anonymous inner classes could be used to override behaviour. https://code.sololearn.com/chJsX8p78r77/?ref=app

+3

Anonymous classes are often used in GUI designs as event handlers. See the Java Tutorials on the subject... https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html

+2

Anonymous class is a class which has no name given to it. Java supports this feature. These classes cannot have a constructor but can have a destructor. These classes can neither be passed as arguments to functions nor can be used as return values from functions.