jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Question Chapter 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Question Chapter 2" Watch "K&B Question Chapter 2" New topic

K&B Question Chapter 2

Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Here is the question from K&B book chapter 2

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.

The answer given is B & F

The explanation given in the book is as follows

When a thread´┐Żs run() method completes, the thread will die. The run()
method must be declared public void and not take any arguments.
A is incorrect because classes can never extend interfaces.
C is incorrect because the run() method is typically not empty; if it were, the thread would do nothing.
D is incorrect because the mandatory method is run().
E is incorrect because the class implements Runnable.

I understand why F is correct, however I am not understanding why B should be correct. The option B says about method run is needed, however does not specify about the access modifier.

On the contrary option C, I feel is correct because it does specify the run method to be public ( which is mandatory condition ). Option C does say about the run method being empty, which I feel should be fine because the question doesn't seem to test on the implementation part of the overridden run method.

Guys, do post your views, I might be missing here something.

[ December 18, 2004: Message edited by: Jay Pawar ]

Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Joe Borderi
Ranch Hand

Joined: Oct 23, 2004
Posts: 151
I understand your quibble with choice B; however, choice C is wrong because it reads "The class must contain an empty public void method named run()" (bold and italics added). If must must were replaced with may, choice C would be correct. The explanation given by the author gives the reason that a programmer shouldn't and not a reason that a programmer can't.

Returning to choice B ("The class must contain a method called run() from which all code for that thread will be initiated."), I read the statement as stipulating a necessary but not sufficient condition.

Reflecting upon the choices, B & F are the best two, per the question's hint, choices. If, however, choice C were rewritten, I believe C would be a better choice than B.
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Thanks for the detailed explanation. Got to be watchful with those words.
I agree. Here's the link: http://aspose.com/file-tools
subject: K&B Question Chapter 2
It's not a secret anymore!