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

Hi Friends, can you give difference between extending thread class and implementing runnable interface.

4 Answers  


What is the Concept of Encapsulation in OOPS

0 Answers   HCL,


What is difference between classpath and path variables in java?

0 Answers  


What is the size of an array?

0 Answers  


Can final class have constructor?

0 Answers  


What are synchronized methods and synchronized statements in java programming?

0 Answers  


What is function declaration?

0 Answers  


Can we print null in java?

0 Answers  


What do you mean by hashing?

0 Answers   Amazon,


Can we iterate through collection using for loop?

2 Answers   Rolta,


What is fail fast in java?

0 Answers  


i need example for java abstraction. where we use abstraction and why we need abstraction.

2 Answers   Oracle,


Categories