• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

barry boone newtest q. 26

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 26: What must be true for the RunHandler class so that instances of RunHandler can be used as written in the code below:
class Test {
public static void main(String[] args) {
Thread t = new Thread(new RunHandler());
t.start();
}
}
Select all valid answers.
a) RunHandler must implement the java.lang.Runnable interface.
b) RunHandler must extend the Thread class.
c) RunHandler must provide a run() method declared as public and returning void.
d) RunHandler must provide an init() method.
The given answer is a and c. I think the answer should only be a since if you say implementing an interface, it already implies that you're implementing the method of that interface.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, if the Runnable interface is implemented, it means the run() method is defined. However, even if the said class has a public void run() method, it may not implement the Runnable interface and then it is wrong.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compiler will complain if you don't provide run() method (which should be public and return void) if a class implements Runnable interface. Hence option A and C are correct.
Hope this helps.
Regds,
Milind
 
Jerson Chua
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Milind...
Does the actual exam has this type of this question which is confusing? I think this depends on your perspective because in my opinion, if you said you implemented an interface, it is implied that all method declared in the interface are already in the implementing class except for abstract class. Actually, this is what I fear most in the actual exam that they may come out with this type of question.
Can anyone shed some light on this topic?
thanks...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jerson,
Some questions in mock tests have poor wordings. I took exam 2 weeks back and the questions in the REAL test were unambigious.
Regds,
Milind

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to add one more thing.It would be sufficient that the RunHandler extend the Thread class and override the run method for the code to run .But this does not necessarily qualify 'b' as answer because extending the Thread class is not a compulsion but impementing the interface and defining the run method is.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer C) is part of the selection. You have no ambiguity in there: just follow this simple reasoning:
"Is C a valid answer?
- Yes, it is a valid answer.
As the question was "Select all valid anwers", just select it!
(You're not required a unique choice: therefore there's no reason for questions to be mutually exclusive!
JRoch
 
Legend has it that if you rub the right tiny ad, a genie comes out.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic