Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Threads

 
Stephan Deve
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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().
 
Atul Chandran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Runnable interface run() is only declared not defined.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I think i got it now.
Thanks for your replies.

greetings
Stephan
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic