• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Static threads - do they exist?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

have been working on the self test questions from sierra & bates, and on question 17 from chapter 9 (threads).



public class TwoThreads {
static Thread laurel, hardy;

... more code goes here ...



my question is that the answer given in the book does not flag up the anomaly of static threads.. surely they dont exist, and therefore the above code would not compile.

Thank you in advance

Tim
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
we can have static object references of Thread that belong to class and not to objects of the class.here in your case static references are declered.there is no notion of static Threads..try code below

class Threads{
static Thread ob = new Thread();
public static void main (String[] args) {
System.out.println(ob);
}
}

Regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic