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 i implemented interface in anonymous class then it shows compiler error why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "i implemented interface in anonymous class then it shows compiler error why" Watch "i implemented interface in anonymous class then it shows compiler error why" New topic
Author

i implemented interface in anonymous class then it shows compiler error why

nagaraj raja
Ranch Hand

Joined: Aug 06, 2005
Posts: 36

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

An anonymous class can either extend another class or implement a single interface. But not both, as you are trying to do.

Note that an anonymous class does not explicitly use "extends" or "implements." Instead, the instance of the anonymous class (defined by the body you include after the constructor call) is automatically upcast to the type of the class or interface that you specify after "new."

So you could do either of the following...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10

Move "implements value" up to the 't' class declaration.



JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
If you do what Marilyn suggests then t must implement the method price or t must be abstract and declare price as an abstract (unimplemented) method.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i implemented interface in anonymous class then it shows compiler error why