Author
Argument defined Annonymous Inner class
Kasak Tahilramani
Ranch Hand
Joined: Apr 06, 2006
Posts: 45
posted Jan 14, 2007 13:56:00
0
1:I am getting error at line 1 ,can someone explain Argument defined Annonymous Inner class with examples.K&B book Ch:8 inner Class. 2:Even my Class Bar is not implementing interface Foo ,how it is implementing the foof() method. Confusion please explain!!!
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
posted Jan 14, 2007 14:27:00
0
Your doStuff method in Bar is defined with no arguments, but you're trying to call it with a parameter.
"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
Kasak Tahilramani
Ranch Hand
Joined: Apr 06, 2006
Posts: 45
posted Jan 14, 2007 14:49:00
0
class Bar{ void doStuff(foo f){} } Even then it is giving error at the same line
Anton Uwe
Ranch Hand
Joined: Jan 10, 2007
Posts: 122
posted Jan 14, 2007 14:56:00
0
You have to use the complete name of the Interface Foo, because it's an inner part of your class Argumentannoys. So you have to write void doStuff(Argumentannoys.Foo x){} or, so that you can see, that your anonymous implementer does his work, void doStuff(Argumentannoys.Foo x){ x.foof(); } [ January 14, 2007: Message edited by: Anton Uwe ]
Kasak Tahilramani
Ranch Hand
Joined: Apr 06, 2006
Posts: 45
posted Jan 14, 2007 16:12:00
0
with which reference variable I can call my public void foof(){System.out.println("foofy"); } and get the output as foofy
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
posted Jan 16, 2007 13:40:00
0
Originally posted by Kasak Tahilramani: with which reference variable I can call my public void foof...
I think Anton answered that question. Does this work for you?
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted Jan 16, 2007 14:02:00
0
I thought this question was answered already in this topic.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
posted Jan 16, 2007 14:22:00
0
Kasak, Once you've posted a question, please continue that discussion in the original thread instead of starting a duplicate thread on the same topic. When there are duplicates, people waste time by responding to questions that have already been answered. Thanks.
subject: Argument defined Annonymous Inner class