• Post Reply Bookmark Topic Watch Topic
  • New Topic

dif b/w extend thread and runnable interface with examples  RSS feed

 
sureesh chowdary
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello to every body ,
last week i went to one interview he asked differnce between b/w thread extends and implementa runnable i explain clearly but he asked wirte a program to differniate each so give examples and diference
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you extend the thread, you override the run method so you can actually do something useful when thread spawns. If you have an object, which already extends from other class, and you still want have some of its code executed in thread, you would use runnable.

By implementing Runnable interface, you can pass that object to a new Thread object and have its run method executed in new thread.

Hope this helps.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FAQ fas something to say about this: ExtendingThreadVsImplementingRunnable
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!