Advantages of Implementing Runnable over extending Thread

Showing Answers 1 - 8 of 8 Answers

Yelisetty Niranjan Prasad

  • Apr 20th, 2006
 

the answer for this question lies in the question itself.it means there is overhead of memomery if we use interface, because for interface there will be runtime overhead which takes time to load. so, in performance critical code we had to avoid interface unless and until it is required.whereas extending thread makes the compiler at the runtime itself to bind the class.But, the code will work same in both ways except the performance.(i dont have an idea wheather it is the correct answer or not, others try to answer this question)

  Was this answer useful?  Yes

ravi

  • Apr 24th, 2006
 

whenever u can extend the Thread class to u r class, u can not extends the other class (because java not support the multiple inhiretence),So most of the devilopers prefer to implements the Runnable interface in place of Thread class.

  Was this answer useful?  Yes

suresh

  • Apr 25th, 2006
 

by impementing the runnable interface we can extend another classes

  Was this answer useful?  Yes

Kiran

  • Apr 26th, 2006
 

 In java there is no multiple inharitence. So if we extend thread class, we can not extend some other. If we use Runnable interface. We can implements any no. of interface.

Thread class is implemented from runnable interface.

Runnable has only single method. i.e run() method.

But Thread class contains no. of methods.

If we want to use only run() method it is better to implement Runnable interface.

If we want to use multiple methods we can go for Thread class.

If any thing wrong in my ans. Pls tel me.

 This is my mail id. kirankumar.km@gmail.com

  Was this answer useful?  Yes

sujata

  • May 23rd, 2006
 

i think ,when we impliment runnable interface ,an object of the thread class must be the member of our program class, and when we extend thread class we need not create an object of thread class in our program. if i m wrong so please tell me.....my ID is sd_wankhede

  Was this answer useful?  Yes

msarada

  • Aug 24th, 2006
 

the reason is, generally we extend a class if we want to enhance or modify the existing class.Thread class has several methods including run().Runnable interface has only one method i.e. run().in any case we must override/implement run() method. if we are not overriding the other methods in Thread class or if we are already extending any other class(for ex Applet)then it is better to implement the Runnable interface.Any how using interface means there will be some performance delays because of redirections so based on the specific need we can do it

  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