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.
TIA
[ December 18, 2004: Message edited by: Jay Pawar ]