• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runnable

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
answer found : c is wrong because of the "must" word
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic