File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonymous Inner Class" Watch "Anonymous Inner Class" New topic
Author

Anonymous Inner Class

ramesh maredu
Ranch Hand

Joined: Mar 15, 2008
Posts: 210

can any one provide me syntax for anonymous inner class that extends a class or implements an interface


SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
Sunil Belurgikar
Greenhorn

Joined: May 21, 2008
Posts: 14
Interface:
Runnable r=new Runnable()
{


public void run() {

}

};


Class:
WindowAdapter f=new WindowAdapter(){};


SCJP 1.6
ramesh maredu
Ranch Hand

Joined: Mar 15, 2008
Posts: 210

Thanks for your reply.
I thought there is special syntax using implements and extends like.

Person person = new Person() implements comparable{
};

Sorry for silly question.
Sunil Belurgikar
Greenhorn

Joined: May 21, 2008
Posts: 14
Interface:
Runnable r=new Runnable()
{


public void run() {

}

};


Class:
WindowAdapter f=new WindowAdapter(){};
Sunil Belurgikar
Greenhorn

Joined: May 21, 2008
Posts: 14
My understanding is that an anonymous class can either extend a class or implement a interface .
Anonymous class can extend a class which implements a interface , in that case anonymous class has to implement interface method in its body.
ramesh maredu
Ranch Hand

Joined: Mar 15, 2008
Posts: 210


Anonymous class can extend a class which implements a interface , in that case anonymous class has to implement interface method in its body.


Anonymous class need not to implement interface method if its super class already implemented.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous Inner Class