• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread questions

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A thread can be created 2 ways: either subclassing (extends) or implement Runnable. What is the difference between the two? Why choose one method over the other? Is there a "is-a" or "has-a" relationship with either of these?
I have been thinking about this for a bit and I just don't know the answer.
Thank you all for your time.
-> scoon
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Threads can be created in two ways.
1.Either by extending "thread" or
2.Implementing Runnable interface.
However,the best alternative is to go for option 2.
Because,in case of option 1(subclassing thread),if a thread needs to extend any additional classes,it is not possible as java does not support Multiple Inheritance.And u know that interface is a replacement for multiple inheritance.This is one primary reason.
 
skip coon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for the response.
how about if either is "is-a" or "has-a" relationship?

thanks, again.
 
praveena kuppachi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as quoted in java2 certification study guide from SIMON ROBERTS:

SUBCLASSING A THREAD HAS AN EFFECT OF SAYING THAT:
"THIS 'IS A' THREAD.
USING RUNNABLE INTERFACE SAYS "THE CLASS IS ASSOCIATED WITH A THREAD "
HOPE THIS WOULD BE CLEAR.
 
skip coon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you. that helps a bunch.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic