What is the use of anonymous inner classes ?
Answer Posted / ashokkumar
Anonymous classes
1.These are one type of inner class that having no mame.
2.The syntax will come like
class a
{
public void mymethod ();
}
class b
{
a obja = new a(){//the anonymous class starts here
public void mymethod (){ //have to implement the methods of
//class 'a'
return "here we are implementing mymethod of class 'a'"
}
}; //when finishing anonymous classes we have to put";"
}
3.Here the anonymous class is consider as a sub class of
class 'a'.We can access all the variables and methods of
super class 'a' through the anonymous block,except local
variables,including private variables.
4.Through anonymous classes we can create instance for
Interfaces.
Is This Answer Correct ? | 19 Yes | 16 No |
Post New Answer View All Answers
What do you understand by a Static Variable?
What is the purpose of an interface?
What is the use of object and class classes?
Is it possible to compare various strings with the help of == operator? What are the risks involved?
What are different types of control structures?
Explain serialization and deserialization in java?
what state does a thread enter when it terminates its processing? : Java thread
Can we sort array in java?
How to sort array in descending order in java?
What is numeric data type?
What is factor r?
How are multiple inheritances done in Java?
What is the use of a conditional inclusion statement in Java ?
What is high level language in computer?
Explain about collection interface in java?