• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

thread questions

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
thank you. that helps a bunch.
 
A timing clock, fuse wire, high explosives and a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic