What is the use of anonymous inner classes ?

Answer Posted / suneetha

The use of anonymous inner classes is to access the data of
outer class.Even private data also we can access.

button.addActionListerner(new ActionListener(){
public void actionPerformed(){}
});

here we are using anonymous class to implement
ActionListener interface.If at all we are using other class
that implements ActionListener interface and passing that
obj into

button.addActionListener(obj);

In this method we cant access the private variables of the
class that call button.addActionListener();

Is This Answer Correct ?    7 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by polymorphism?

532


Is string a datatype?

550


Does java isempty check for null?

568


What is the difference between heap memory and stack memory?

613


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

557






Convert a BST into a DLL and DLL to BST in place.

665


What is the purpose of checked and unchecked exceptions in JAVA?

564


What does the string method compareto () do?

535


What does substring mean?

507


What is internal iteration in java se 8?

625


What is a lock or purpose of locks in java?

586


Define linked list and its features with signature?

537


What are the advantages of packages in java?

569


What are different types of encoding?

578


What are the four pillars of java?

608