• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

tricky thread qn

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

answer is e as non static method start() can not be referenced from static context.
but in the following code

it compiles fine, although a.start() has been referenced from static context.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the second code start is associated with a object unlike the code in 1 where non static method start() is not associated with any object

to call a non static method frm a static method it must have a objkect associated with it
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question would have been much nicer if it was a real Thread-programming question and not one which just aims you to overlook that start() is called illegally. Anyway. What do you think would be the answer if we modify only the main() method like this:

[ February 14, 2006: Message edited by: Peter Petrov ]
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question.
Answer will always be 'ABC' because..

The run method waits until sa[0] contains a value 'Done'. If sa[0] gets a value of 'Done' then it is guaranteed that sa[1] + sa[2] + sa[3] is 'ABC'
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic