• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Boone's Question on Threads

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Here is a question from Boone's Mock Exam Question 46 from the link
Boone's Mock Exam

What is the correct answer? (please give explanation)

If you supply a target object when you create a new Thread, as in:

Thread t = new Thread(targetObject);

What test of instanceof does targetObject have to pass for this to be legal?

Select the one right answer.

1. targetObject instanceof Thread
2. targetObject instanceof Object
3. targetObject instanceof Applet
4. targetObject instanceof Runnable
5. targetObject instanceof String

My Ans:
targetObject may be true for instanceOf Thread, Object, Runnable or String.
Since Object is the superclass of all objects should that be correct answer?

and also Does anyone know where I can find answers for Boone's Mock Exams.
I don't see any link on the Exam page.

Thanks.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lakshmi,

and also Does anyone know where I can find answers for Boone's Mock Exams. I don't see any link on the Exam page.

Boone's mocks:
Question 1-19
Question 20-39
Question 40-70
Answer 1-70

My Ans:
targetObject may be true for instanceOf Thread, Object, Runnable or String.
Since Object is the superclass of all objects should that be correct answer?


The answer given in Boone's answers is 4 (or d). IMO, option 1 should be correct as well because Thread implements Runnable. Now come to option 5, should this be the correct answer depending on how the author defines targetObject. Obviously (but only after I read the API) the author extracts the word target from the parameter's name of Thread constructor. So this one is open to interpretation. Option 2 is incorrect because passing instanceof Object test doesn't mean targetObject is Runnable. According to the Thread API, for single parameter, the constructor can only accept either String or Runnable instance.

Joyce
[ July 22, 2005: Message edited by: Joyce Lee ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't think we can pass an object as an argument.
Object is the supercalss of all other classes. but we can't cast a superclass to subclass.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me illustrate with example as to why option 2 is incorrect.



Both passed the instanceof test. However, only targetObject2 can pass in as an argument to Thread constructor.
[ July 22, 2005: Message edited by: Joyce Lee ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic