java - Why should I use Runnable instead of Thread? -


this question has answer here:

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

Popular posts from this blog

java - Null response to php query in android, even though php works properly -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -