• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about thread and Runnable interface

 
sujit kanase
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does Runnable implements Thread Class
and which is better to use thread or Runnable and why?
 
srikanth reddy
Ranch Hand
Posts: 252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sujit

Thread class implements the Runnable interface ...

As far as second question i dont think there is any problem in using either ..anyone is OK ....

thanks

srikanth
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if your class extends some other class...and you need introduce concurrency in your class then you might be tempted to implement the Runnable Interface.
Otherwise you always have the option to extend Thread Class.
 
Shweta Dhaneshwar
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does Runnable implements Thread Class
and which is better to use thread or Runnable and why?


for you 1st question the ans is a class can implement a interface or can extend a class.An interface can extend an interface.So the Runnable interface does not implement Thread Class.

I think we should use Runnable interface coz if your class extends Thread class...then you cannot extend another class(multiple inheritance not allowed in java)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic