This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonymous Class" Watch "Anonymous Class" New topic

Anonymous Class

Pradeep Balasubramanian
Ranch Hand

Joined: Jun 16, 2008
Posts: 75

For the code above,
how to call the nowsee method in the main function ?

Regards,<br />Pradeep Balasubramanian<br /> <br />You have to grow from the inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul. <br /> <br />- Swami Vivekananda
Antonio Tercero
Ranch Hand

Joined: Jun 05, 2008
Posts: 110
You can't call the method from main function.
Anonymous classes are used to pass a specific implementation as an argument of a method.
In your code, doStuff() method will be able to invoke nosee() method to perform some stuff but you can't access nosee() method from main.

You will understand better the concepts (why and when using anonymous classes) in chapter about Threads: there are a lot of examples regarding anonymous classes (implementation of a specific run() method from Runnable interface )

It is sorta covered in the JavaRanch Style Guide.
subject: Anonymous Class