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 are the two ways in which thread can be created?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
Which data type is class in java?
What do you mean by data type?
What is array list in java?
State the difference between strings and arrays.
What is the difference between a factory and abstract factory pattern?
What do you mean by collectors in java 8?
Can we have two main methods in a java class?
What is arrays sort in java?
Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?
What are different exception types exceptions available in java ?