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 Runnable 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 "Runnable" Watch "Runnable" New topic
Author

Runnable

Valentin Munteanu
Greenhorn

Joined: Feb 06, 2003
Posts: 5
hi in McGraw Hill- Sun Certified Programmer & Developer for Java2, chapter 2, question 14 valid answers are b and f.
Here is the question :
Which two statements are true for any concrete class implementing the
java.lang.Runnable interface? (Choose two.)
A. You can extend the Runnable interface as long as you override the public run()
method.
B. The class must contain a method called run() from which all code for that thread will
be initiated.
C. The class must contain an empty public void method named run().
D. The class must contain a public void method named runnable().
E. The class definition must include the words implements Threads and contain a
method called run().
F. The mandatory method must be public, with a return type of void, must be called
run(), and cannot take any arguments.
I can not understand why b is correct ? Instead b i would choose c. Where I'm wrong?
Valentin Munteanu
Greenhorn

Joined: Feb 06, 2003
Posts: 5
answer found : c is wrong because of the "must" word
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
As far as I can tell, B and F are the correct answers. Here is why:
A is wrong because a class cannot extend an interface
B is true because this is how the thing work with thread when implementing the Runnable interface, i.e. all the stuff that should be executed by the thread must be put in the run method
C is wrong because if you don't put anything in the run method, nothing is gonna happen.
D is wrong because no such method exists in the Runnable interface
E is wrong because a class cannot implement another class (Thread)
F is true because the description fits perfectly the signature of the run method contained in the Runnable interface.
[ July 14, 2003: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
Valentin, indeed you might get confused because of the "must" keyword. The way in which C is formulated it means that the run() method must be empty. Which is of course not true. However it could be empty (and the thread in that case would do nothing). So if the answer would be:
C. The class could contain an empty public void method named run().
answer C would be completely valid.
On the other hand I agree B is not completely true. The run method must be public in a class which implements the Runnable. And B does not specify this (even though is specified in B that it is public). F is definately the most complete answer. So I would say just go over this question, since at the exam the questions are more clearly formulated.
Good luck,
Miki


Miki<br /> <br />SCJP 1.4, SCBCD 1.3
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
Here's the dilemma I see with answer b. It forward references information that is covered later in the book. The reason we did that is because on the real exam questions will often involve knowledge that spans several objectives.
So it might not be totally fair in the context of chapter 2 if chapter 2 was stand alone entity, but in the context of the entire book I believe it is a good, representative example of what you'll see on the real exam.
My advice is to review all of the end of chapter questions once you have read the first nine chapters. Some questions that may have been hard the first time will be easier once you have the entire context of the objectives under your belt.
Good luck!
-Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Runnable