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
Where import statement is used in a java program?
Difference between error and exception
What does split function do in java?
What is the difference between processes and threads?
What is jit compiler ?
What is oop in java?
What is memory leak and how does java handle it?
What is the use of StringTokenizer class?
What is thread pool in java with example?
What is an accessor?
What is a numeric digit?
What is a concrete classes? Is Java object class is concrete class?
When do you get classcastexception?
What is boolean keyword in java?
What are the different types of inner classes?