This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonymous inner class" Watch "Anonymous inner class" New topic
Author

Anonymous inner class

naveena kamsali
Greenhorn

Joined: Sep 20, 2011
Posts: 8
hi friends,

can anyone tell about, how to call a method inside anonymous class which is created in a method.


Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Sorry, do you mean calling a method belonging to the anonymous inner class, or calling another method from within an anonymous inner class?

Anyway, in both cases you just call it like any other method, as long as you have a reference to the object that you want to call the method on. For instance, within your Bar.foo() method you can just call:
It doesn't matter whether the Foo passed in was created as an anonynous inner class or a conventional class - either way you can still call the methods of the Foo interface on it.

If that doesn't answer the question, can you be a bit more specific about what you mean?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Anonymous inner class
 
Similar Threads
Argument-Defined Anonymous Inner Class
Argument defined Annonymous Inner class
Anonymous inner class
Argument-defined anonymous class call
Anonymous class