File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about Threads" Watch "Question about Threads" New topic

Question about Threads

Stephan Deve

Joined: Sep 21, 2004
Posts: 13
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

Class Thread

Interface Runnable

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 ??

Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97

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

Thread implements runnable and defines run().

Jimmy Die
Atul Chandran

Joined: Oct 24, 2004
Posts: 22
In Runnable interface run() is only declared not defined.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Atul Chandran:
In Runnable interface run() is only declared not defined.


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.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Stephan Deve

Joined: Sep 21, 2004
Posts: 13
I think i got it now.
Thanks for your replies.

I agree. Here's the link:
subject: Question about Threads
It's not a secret anymore!