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

1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?

2 Answers   TCS,


Can we override the overloaded method?

0 Answers  


What is a line break?

0 Answers  


What makes a function well defined?

0 Answers  


When throws keyword is used?

0 Answers  






What is variable explain with example?

0 Answers  


What services that container provides?

2 Answers  


Explain try and catch keywords in java?

0 Answers  


What is the difference between object oriented programming language and object based programming language?

0 Answers  


explain System.out.println

107 Answers   Calpine Technologies, Care, Cognizant, CTS, IBM, IBS, LibSys, Oracle, Spiro Solutions, TCS,


Define inheritance?

0 Answers  


Java.util.regex consists of which classes?

0 Answers  


Categories