wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread" Watch "Thread" New topic
Author

Thread

Prashant Ameta
Greenhorn

Joined: Jul 17, 2012
Posts: 11
Hii,I have a question Regarding threads
There are two ways to create a thread-
1.)by Extending the Thread class
2.)by implementing Runnable interface
which one is better and how would one decide???

Thanks in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Please SearchFirst. This question has been asked and answered several times before.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Prashant, always write a meaningful name of Topic when you post.


OCPJP 6 86%
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

The answer to this question doesn't have much to do with multithreading. It's more about inheritance and class design in general.
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Prashant Ameta wrote:Hii,I have a question Regarding threads
There are two ways to create a thread-
1.)by Extending the Thread class
2.)by implementing Runnable interface
which one is better and how would one decide???

Thanks in advance


Answers-
1.)When do you extend a class ??
2.)When do you implement an interface ??

as Jeff Verdegan have already told you that this question is more about inheritance and class design.
Then If you can answer these question then you can answer your own questions too.
If you can't answer these then you should study more about inheritance first before start Thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread