This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to instantiate anonymous inner class? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to instantiate anonymous inner class?" Watch "how to instantiate anonymous inner class?" New topic
Author

how to instantiate anonymous inner class?

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1145



how can i use run method of anonymous inner clas???


No Kaustubh No Fun, Know Kaustubh Know Fun..
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1145

and in case if we not what is the use of it?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

your code allowed you to write the code there rather than requiring a separate Class.
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1145

but what is the use of the code when i am not able to access it. How can i access it?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32704
    
    4
You instantiate an anonymous class the same way you instantiate any class, with the new operator/keyword. There is an example of how it is done in this post.
You assign it to a reference the same way you assign to any other reference, like this: Foo f = . . .
You call its methods exactly the same way you call methods on any other reference, like this f.bar(123, 456);
You could call its run() method like this r.run();, but you would actually say something like new Thread(r).start();
prem pillai
Ranch Hand

Joined: Nov 02, 2007
Posts: 87


Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1145

thanks prem
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to instantiate anonymous inner class?
 
Similar Threads
how to start a thread??
argument anonymous class
Annonymous Inner class problem
Initializing instance variables in java
anonymous inner class output