Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anonymous Class

 
Pradeep Balasubramanian
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

For the code above,
how to call the nowsee method in the main function ?
 
Antonio Tercero
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic