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


Please Help Members By Posting Answers For Below Questions

Is it possible to compare various strings with the help of == operator?

546


Can we initialize the final blank variable?

578


What is temp in java?

549


What is the difference between dom and sax parser in java?

528


How thread scheduler schedule the task?

581






What are the different collection views provided by maps?

563


What is yield () in java?

478


What is hashing in java?

563


Can string be considered as a keyword?

566


What do you mean by collectors in java 8?

537


What is scope & storage allocation of static, local and register variables? Explain with an example.

560


What is compareto () in java?

535


Why java is said to be pass-by-value ?

542


What is synchronization and why is it important in java programming?

469


What is the maximum size of byte array in java?

538