| 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: 9033
|
|
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.
|
 |
 |
|
|
subject: i implemented interface in anonymous class then it shows compiler error why
|
|
|