what is an anonymous class?

Answer Posted / venki

3) Anonymous classes:
1. A class which doesn’t have any name is called anonymous class and which is a type of inner class. It can be either member class or local class.
2. It is a sub class that extends a class or implements an interface but not both. It can implement only one interface.
3. These are used where implementation of methods various from one object to another object. Anonymous class is final class.
4. public class Demo{
A a=new A();
a.m1();
A 1=new A(){ void m1(){ --- }};
a1.m1();
}
On compiling this above program the java compiler generates A.class, Demo.class and Demo$1.class (Anonymous class).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we define private and protected modifiers for the members in interfaces?

527


How many bits is a string?

517


Can extern variables be initialized?

501


Name few "optional" classes introduced with java 8 ?

639


If two threads have same priority which thread will be executed first ?

837






What is a parent class in java?

537


Explain wrapper classes in java?

522


What is a dynamic array java?

503


how can you take care of mutual exclusion using java threads? : Java thread

599


What is null statement?

524


How can you generate random numbers in java?

577


What is difference between == equals () and compareto () method?

519


java Technical questions asked by JPMC

4563


What is string subsequence method?

621


how to run ecllipse with jettyserver for windows environment using batch file

1482