aspose file tools*
The moose likes Beginning Java and the fly likes Doubt in threading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt in threading" Watch "Doubt in threading" New topic
Author

Doubt in threading

Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361

Hi, in the above code,I made an anonymous inner class and defined the run method in it. But I didnt extends the thread class or implement runnable. how am I being able to to do? the code runs fine and prints hello.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Amitabha Batranab:
I didnt extends the thread class or implement runnable.


Yes, you did. The anonymous inner class extends Thread.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Mandeep kaur
Greenhorn

Joined: Aug 13, 2006
Posts: 8
anonymous class is created and instantiated at same time.it can be created from by extending any class or interface and extends keyword is never used. when made from a class its format is :-
new superclassName(argument list){
//Body of this class
};
So when you do this following things are done:-
1.constructor of superclass is called,If you dont specify any argument then the default constructor of superclass is called else the argument constructor corresponding to arguments you passede is called
2.Object of this anonymous class is crated using new.
when anonymous class is created from any interface as its supertype format is:
new interface name(){
//Body of this class
};

hope now the concept of anonymous class is clear
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in threading
 
Similar Threads
Thread doubt
Doubt in inner class
Question about the join method in Thread
What Happens If a thread Can't Get the Lock?
synchronized and Thread