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

Is null or empty java?

0 Answers  


Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.

0 Answers   Amdocs,


What is the use of jtable?

0 Answers  


I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?

0 Answers  


What is finalize()? Is finalize() similar to a destructor?

0 Answers  


if arraylist size is increased from initial size what is the size of arraylist...suppose initial is 100 , if i add 101 element what is the size...

10 Answers  


What do you understand by a Static Variable?

0 Answers   CGI,


How do you override a variable in java?

0 Answers  


What are autoboxing and unboxing? When does it occur?

0 Answers  


What are some alternatives to inheritance?

0 Answers  


Name the methods in mouse listeners ?

4 Answers  


could you run the java program without main method?

6 Answers  


Categories