Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

Argument defined Annonymous Inner class

 
Kasak Tahilramani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Report post to moderator


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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
Your doStuff method in Bar is defined with no arguments, but you're trying to call it with a parameter.
 
Kasak Tahilramani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Report post to moderator
class Bar{

void doStuff(foo f){}
}

Even then it is giving error at the same line
 
Anton Uwe
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Report post to moderator
with which reference variable I can call my
public void foof(){System.out.println("foofy");
}

and get the output as foofy
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
I thought this question was answered already in this topic.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic