What is the difference between extending Thread class and implementing Runnable interface?which one to prefer/use? why?

Questions by gnr

Showing Answers 1 - 4 of 4 Answers

hiSee ,the purpose of both of these is same,i.e creating threads.when we extend thread this means that we are extending a thread class.Thread is a class which may have functions ,data members.When v extend , we can overwrite them.In java there is no concept of multiple inheritance.Therefore at a time only one class can extend if.Runnable interface is an interface,i.e it will contain variables and functions will be declared without defintions.The most imp thing about interfaces is that 2 or more classes can implement interfaces at a time.

  Was this answer useful?  Yes

t.s.saravanan

  • Apr 9th, 2006
 

if the class extends the thread, the methods in the class thread are over ridded and the class which extends the thread should run as thread appliciation.most prefarable way of creating the thread is using runnable interface because a class can implement any number of interfaces.  

  Was this answer useful?  Yes

Amrita

  • May 11th, 2006
 

A thread can be started only once. If you need to start a thread more than once then implement the runnable interface, you can create and start as many threads as you want with the same target.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions