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
Is it possible to compare various strings with the help of == operator?
Can we initialize the final blank variable?
What is temp in java?
What is the difference between dom and sax parser in java?
How thread scheduler schedule the task?
What are the different collection views provided by maps?
What is yield () in java?
What is hashing in java?
Can string be considered as a keyword?
What do you mean by collectors in java 8?
What is scope & storage allocation of static, local and register variables? Explain with an example.
What is compareto () in java?
Why java is said to be pass-by-value ?
What is synchronization and why is it important in java programming?
What is the maximum size of byte array in java?