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 are the differences between graph and tree?
Explain thread in java?
Which language is java?
Why javac is not recognized?
What is a method signature java?
Is zero a natural number?
Write a function to find out longest palindrome in a given string?
How many types of exception can occur in a java program?
What is the relationship between clipping and repainting under awt?
Can each java object keep track of all the threads that want to exclusively access it?
Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?
How do you get length in java?
What is treeset in java?
What are different types of references?
What is assembly language?