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 c++ and java?
Java.util.regex consists of which classes?
How do you do a line break in java?
What is import java util arraylist?
What is instance means in java?
What is :: operator in java 8?
What is class variable java?
Can we write multiple catch blocks under single try block?
What is the difference between variable declaration and variable initialization?
What is the difference between inner class and nested class?
Is java jre still free?
What are the legal parameters?
Why is flag used in java?
What is private public protected in java?
What types of index data structures can you have in java?