• 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

Question about Threads

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i am not sure about one answer in the book of Kathy Sierra and Bert Bates.

On Page 534 you find a table that says which methods belong to which class:

Class Object
wait()
notify()
notifyAll()

Class Thread
start()
yield()
sleep()
join()

Interface Runnable
run()

The Question is Question:
Which two of the following methods are defined in class Thread?
A. start()
B. wait()
C. notify()
D. run()
E. terminate()

Depending on the table i would say only A is correct, but the correct answer:

Correct: A and D. Only start() and run() are defined by the Thread class.
Uncorrect: B and C are incorrect because they are methods of the Object class. E is incorrect because there�s no such method in any thread-related class.

So my question is: Why is D correct ? I think it belongs to Thread.
Or is the answer so simple that tread implements runnable ??

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

It is as you say. Read the documentation for thread in java.lang.

Thread implements runnable and defines run().
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Runnable interface run() is only declared not defined.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Atul Chandran:
In Runnable interface run() is only declared not defined.



True.

Thread implements Runnable by having a run method:




The target, if it is non-null, is the Runnable object passed through to the Thread constructor.
 
Stephan Deve
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think i got it now.
Thanks for your replies.

greetings
Stephan
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic