• 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

threads

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
a. targetObject instanceof Thread--true
b. targetObject instanceof Object--true
c. targetObject instanceof Applet
d. targetObject instanceof Runnable//true
e. targetObject instanceof String //true
My answers are based on the ctors that are passed
Am i correct???
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Look up the constructors that actually exist for Thread.
 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread(Runnable )
Thread(String)

a. targetObject instanceof Thread--false
b. targetObject instanceof Object--false
c. targetObject instanceof Applet//false
d. targetObject instanceof Runnable//true
e. targetObject instanceof String //true

I messed up my ctor check previously......
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
targetObject instanceof Object is also true
Sri
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread t = new Thread(targetObject);
What test of instanceof does targetObject have to pass for this to be legal?
Select the one right answer.
a. targetObject instanceof Thread--true
b. targetObject instanceof Object--true
c. targetObject instanceof Applet
d. targetObject instanceof Runnable//true
e. targetObject instanceof String //true
its true that instanceof object is true may be the compiler wouldnt catch but wouldnt the runtime squak at it ???
well (d) is what i would choose but for argument sake lets continue this
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prem,
Object class is great grandfather of everything
It doesnt even complain at runtime.
provided instanceof can targetobject is ofcourse a String or Runnable target. If it is either of the above, then it is also an instanceof Object.
So if String and Runnable can return true for targetObject instanceof, then Object is also correct
Isnt it right or am i missing something ?
Sri
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic