Reply
Class inside a Method in JAVA
Old 07-10-2007, 08:28 AM Class inside a Method in JAVA
Novice Talker

Posts: 5
Name: prakash
Can we define a class inside a method in JAVA.

If so can u show the code samples, for better understanding



Prakash
mvsprakash is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 07-10-2007, 10:20 AM Re: Class inside a Method in JAVA
willcode4beer's Avatar
Webmaster Talker

Posts: 602
Name: Paul Davis
Location: San Francisco
Quote:
Originally Posted by mvsprakash View Post
Can we define a class inside a method in JAVA.

If so can u show the code samples, for better understanding


Prakash
This is a Java not javascript question so, it probably belongs down in the 'coding forum'.

Yes, however, it would be an anonymous inner class. Generally, to be avoided but, there are cases to use it.

For example, here is a trivial case (though bad example) to start a new thread to run a task asynchronously.
Code:
    public void foo(){
        // do stuff
        Thread thread = new Thread(new Runnable(){
            public void run() {
                // do some long running task asynchronously
            }});
        thread.start();
        // do other stuff
    }
__________________
Paul Davis
willCode4Beer.com (coding for all the right reasons)
willcode4beer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Class inside a Method in JAVA
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11499 seconds with 13 queries