This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Doubt in threading
 
Similar Threads
Question about the join method in Thread
What Happens If a thread Can't Get the Lock?
Thread doubt
Doubt in inner class
synchronized and Thread