java - Why should I use Runnable instead of Thread? -
this question has answer here:
- “implements runnable” vs. “extends thread” 37 answers
i learn theory thread. , there thread , runnable.
class extends thread{ public void run(){ while(true) { system.out.println("hi"); } } }
class b implements runnable{ public void run(){ system.out.println("hi"); } }
thread rich api, why use runnable instead of thread?
thanks.
1. java doesn't support multiple inheritance, means can extend 1 java class, once extended thread
class lost chance , cannot extend(inherit) class in java.
2. in oop extending class means adding new functionality, modifying or improve behaviors. if not making modification on thread
, use runnable
interface instead.
3. implementing runnable
makes class more flexible(you can implement more 1 interface).
Comments
Post a Comment