Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of creating a Thread by extending a Thread class [duplicate]

Tags:

java

runnable

Possible Duplicate:
Java: “implements Runnable” vs. “extends Thread”

Java provides two options to create a Thread class i.e either by implementing Runnable or by extending Thread class.

I know there can be many reasons to implement a Runnable but not sure where the scenario would be to extend a Thread class to create own Thread class?

Could you please provide me scenarios where extending Thread seems to be feasible or better option or advantageous...

There was a Question on the threads but that did'nt answer my question

like image 600
Satya Avatar asked Jun 17 '12 18:06

Satya


1 Answers

There is almost no reason to extend Thread, basically the only reason you would want to extend thread is if you were going to override things other than run() which is generally a bad idea. The reason it is less common to extend Thread is because then the class can't extend anything else, and if you're only overriding the run() method, then it would be kinda pointless to extend Thread and not implement Runnable.

like image 128
John Avatar answered Sep 21 '22 06:09

John