This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
adapter,anonymous
Posted by tejinder singh on June 01, 2001 at 1:46 PM
hi the use of adapter class lies in using only the methods we want rather than have to implement all the methods of the interface. for e.g if we implement an interface say WindowListener then instead of overriding all the methods of windowlistener we can extend windowadapter and use only the method we want.as windowclosing()etc. anonymous class is used in situations where the instance of class is not used for any other purpose and is specifically created for one particular use only for instance when passing the instance of the class which acts as the listener to any event to the method addxxxlistener() we can pass an anonymous class as the parameter to it as addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { } } ) here the ActionListener() indicates that the anonymous class implements ActionListener.This class has no name so no constructor and also objects cannot be created. hope this clears tejinder
Replies:
|