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

What is default constructors?

535


Difference between doublesummarystatistics, intsummarystatistics and longsummarystatistics ?

541


What is a text string?

613


how would you implement a thread pool? : Java thread

499


If a class is declared without any access modifiers, where may the class be accessed in java programming?

649






What is the r character?

582


What type of variable is gender?

537


How do I remove a character from a string in java?

492


What is the meaning of variables in research?

522


When can you say a graph to be a tree?

632


what is use of functional interface in java 8?

552


Why java is object oriented?

579


Why is the type for real numbers called double?

540


What is meant by collection in java?

539


How do you calculate square roots?

566