• 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 strategies

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strategy # 1: extend the Thread class; this will put the run method in a subclass of Thread and may mean that the method cannot get to the features it needs (Java 2 Cert. Study Guide,Roberts & Heller, page 203). Can anyone give me a example on how this would limit access?
Strategy # 2: implements Runnable - the good way: because: "The run()method, like any other member method, is allowed to access the private data, and call the private methods, of the class of which it is a member (Java 2 Cert. Study Guide,Roberts & Heller, page 203)."
I'm don't get what they mean, are they saying if you create a instance of the class the run method is in you can then access any private data in it?
Can anyone give a simple example of the two ways, please! What difference would the 2 ways make? I could still create a instance of both classes and access any private data.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a class X which subclasses class A, then how can X subclass Thread (as Java does not allow multiple inheritance). If X were to subclass Thread, then members of X cannot inherit from A. I think that this is what is meant by "may mean that the method cannot get to the features it needs".
 
donald rieck
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're right! Thank you so much for clearing the fog!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic