What is an anonymous class?
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 |
What is the difference between int and integer in java?
How to sort list of list in java?
Explain about automatic type conversion in java?
If we allocate the memory using 'new' & de-allocated using 'free' then what will happen?
Explain the difference between a Thread and a Process.
int a=1,b=10; System.out.println(a+b--);
Is it safe for adding 10,00,000 records/objects to HashMap?, i.e is it safe to add millions of objects to HashMap?
Can an unreachable object become reachable again?
Can we call virtual funciton in a constructor ?
how and when compiler knows that the Java code throws the checked Exception.
what is the difference between abstract class and Interface?where we can use it in realtime projects?
23 Answers Agile Software, Cognizant, IBM, Innodata, Logica CMG, Mitosis, Nagarro, Value Chain,
Can we override the static method?