+ 1
What is the use of Anonymous class?
2 Answers
+ 1
You can basically create an instance if a class with your own parameters and own implementations of methods without having to create an own file.
For example an Actionlistener
Button b=new Button;
b.addActionlistener (new Actionlistener (){@override
public void actionPerformed (ActionEvent e){ some code that executes when you press the button}});
You use them as in the example if you want a class extending an other class (actionlistener) that you would only need one time. (normally there shouldnt be the same happening when you press several different buttons)
in java 8 they got a littlebit useless because of lambda expressions.
0
Simplest answer to this question is that, we can instantiate a class without making an actual seperate class.