This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
nagaraj raja
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic