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
Does java support Operator Overloading?
What is the difference between a choice and a list?
What are recursive functions?
What is the largest number a double can hold?
What is flush buffer?
Where are the card layouts used?
What is bufferedwriter?
Is a class subclass of itself?
What are access specifiers available in java?
How many bytes is double?
How do you sort a string in java?
Explain the JDB in depth & command line.
what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread
Is java good for beginners?
Explain when we should make an instance variable private.