This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 9079
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
Boost this thread!