File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Question about Threads

Stephan Deve
Greenhorn

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

Joined: Nov 20, 2003
Posts: 97
Hi,

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

Thread implements runnable and defines run().


Jimmy Die
Atul Chandran
Greenhorn

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.


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.


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
Greenhorn

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

greetings
Stephan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about Threads