What is the use of Anonymous class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the use of Anonymous class?

26th Jul 2016, 5:00 PM
Samiksha Rathore
Samiksha Rathore - avatar
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.
26th Jul 2016, 6:09 PM
No One
No One - avatar
0
Simplest answer to this question is that, we can instantiate a class without making an actual seperate class.
18th Nov 2016, 5:25 PM
Animesh Patra
Animesh Patra - avatar