What is an anonymous class?

Answer Posted / sai

An anonymous class is a local class without a name. An
anonymous class is defined and instantiated in a single
succinct expression using the new operator.

Example:
class popcorn{
public void eat(){
syso("popcorn is sweet");
}
public void m1(){
syso("popcorm method");
}
class sample{
public static void main(String args[]){
popcorn p = new popcorn(){
public void eat(){
syso("popcorn is so hot");
}
};
p.eat();
p.m1();
}
}

Is This Answer Correct ?    17 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is tree Mirroring implemented?

627


Which package is imported by default?

630


Explain jdk, jre and jvm?

567


Explain when noclassdeffounderror will be raised ?

614


What is a literal coding?

509






What do you mean by global variable?

522


What is a newline character in java?

563


What is string example?

595


What is enhanced loop in java?

546


Can we use return in constructor?

486


what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread

557


How to invoke external process in java.

559


What is the difference between Java and C++?

610


What are the data types supported by java?

542


what is the volatile modifier for? : Java thread

519