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

What is volatile keyword in java

650


Can inner class have constructor?

552


How do you sort arrays in java?

528


Difference between Preemptive scheduling vs. Time slicing?

575


How many types of methods are there?

550






Why do we use bufferedreader?

542


How does arraylist size increase in java?

531


What is package protected in java?

528


Why we used vector class?

632


Enlist few advantages of inheritance?

587


What is final int?

534


Can we write multiple catch blocks under single try block?

577


Can I override protected method in java?

600


What is java oops?

560


Can a class have multiple subclasses?

588