What is an anonymous class?



What is an anonymous class?..

Answer / 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

More Core Java Interview Questions

Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?

0 Answers  


when there is a need of jvm then how we can say that java is a platform independent language?

3 Answers  


i would like to attend for an interview of datalab technologies company i want to know the pattern of imnterview.

0 Answers  


What is thread safe in java?

0 Answers  


Matrix multiplication only using OOP concepts .

0 Answers  






Is vector ordered in java?

0 Answers  


Can inner class extend any class?

0 Answers  


What do you mean by of string::valueof expression in java 8?

0 Answers  


Is treeset sorted in java?

0 Answers  


Which collection allows duplicate values in java?

0 Answers  


What is a method ?

6 Answers  


How to reverse a string in java?

0 Answers  


Categories