• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

parameters for Thread constructor (Q46 from Boone�s exam)

 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 46 from Boone�s exam
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
b. targetObject instanceof Object
c. targetObject instanceof Applet
d. targetObject instanceof Runnable
e. targetObject instanceof String
This question was already discussed and decision was:
D is the only correct answer
A & E are possible parameters for Thread constructor, but targetObject DOESN�T HAVE to be of type Thread or String for Thread t = new Thread(targetObject) to compile.
My doubts:
1) String is a valid parameter for Thread constructor, so the construction above will compile.
2) Object of String type definitely will not pass instanceof Runnable
3) Therefore d is not correct answer
4) B is the only correct answer
What do u think?
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mapraputa,
Can u please give me the link to Boone�s exam.
Thx in Advance.
Aruna
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The target is Runnable which Thread implements. String is not Runnable, so passing a name for the string doesn't run the questioned constructor.
A - wrong because I can pass my own Runnable class as in
new Thread(new Runnable() { public void run() {} });
B - wrong because Object doesn't mean you implement Runnable.
C - get real
D - Correct!
E - calls constructor with (String) signature, also I guess you could have a String that implements Runnable, but testing for String doesn't test Runnable.
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aru:
Boone�s exam is here: http://www.geocities.com/SiliconValley/Orchard/9362/java/javacert/newboone1-19.html
I found it on Maha�s page: http://www.javaranch.com/maha/_Mock_Exams/_mock_exams.html - there are a lot of links to other mocks also.
Scott:
I think the problem is how to understand the question: �What test of instanceof does targetObject have to pass for this to be legal?�
My interpretation: if targetObject fails some test, the sentence
Thread t = new Thread(targetObject);
is illegal (doesn�t compile)
In this sense if targetObject is not an instance of Object, which can happen only if targetObject is of primitive data type, our sentence will not compile: there is no constructor accepting any primitive data type in Thread class.
We cannot have String that implements Runnable. It would be possible if we could subclass String and make a subclass implement Runnable. We cannot do that because String class is declared as final.
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correction:
The phrase �What test of instanceof does targetObject have to pass for this to be legal?� may be understood in two ways:
Meaning # 1:
if targetObject fails a test,
Thread t = new Thread(targetObject);
doesn�t compile
answers: b
Meaning # 2:
if targetObject passes a test,
Thread t = new Thread(targetObject);
WILL compile
answers: a d e
But in neither case is �only d� correct answer.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely you are Joking Mr.
the question is abourt the constructor
Thread(Runnable target)
and not
Thread(String name)
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mapraputa,
I agree with mohit joshi in the view that this question is basically about the valid constructors that needs to be passed.
Also, the question clearly has a phrase "have to". Therefore, I'd choose, a, d, e as valid answers coz
a) Quite St fwd and Thread implements runnable
d)TRUE, I hope everbody agrees to this
e) TRUE, coz Thread does have a construct as String and it is equivalent of Thread(null, null, name) for the constructor
public Thread(ThreadGroup group, Runnable target,String name)
Now c) is false - I guess there is no issue on this
-sampaths
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mohit joshi:
No, I am not joking. I remember smbd Certificated said that s/he liked badly worded questions from mocks because they made us think.
I also understood this question as �which constructors are valid�. But then I read what Jim Yingst said (url is in my first message):


If you say a is true, that means that targetObject must pass the test (targetObject instanceof Thread) in order for the code to compile. This is not true - it may pass that test, in which case the code will definitely compile, but it does not have to.


- this interpretation is also possible!
What puzzled me, that I couldn�t see how �only d� (as many experts said) may be corrects answer.
I like this question, because IMHO regardless of what is the right answer it shows how important it is to read question carefully and think �what it means� before answering.
Hi Sampaths!
So you vote for meaning # 2. Do you think this is the only correct interpretation, or you just prefer it to m # 1?
 
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
Mapraputa,
From the word "legal", I interpret that the question is asking only about successful compilation.
And, I would interpret the question in Mohit's 2nd interpretation.
IMO, we shouldn't really dissect every word in the sentence and try to interpret. Also, we may be better off by trying to figure what the examiner's inetntions are behind asking this question. I apply this technique when I find the question is ambiguos.
Fortunately, the questions in the exam are not ambigous and 99% of the times you'll interpret just one meaning.
-sampath
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FWIW IMHO AFAIK ETC: D is the only answer.
Surely we agree that the name chosen for a formal parameter
should affect nothing, correct? So rewrite the question
like this:
If you supply a target object x when creating a new Thread, as in:
Thread t = new Thread(x);
What test of instanceof does x have to pass for this to be legal?
Then my answer is that if x is a String, the code will compile
and run fine, but x will not be a target object, it will
be a thread name, so that case simply is not asked about by
this question.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am moving this topic to Threads and Synchronization
Ajith
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Jim!
"target object" - that makes sense. I did not understand what "target object" means and decided that if Strings are objects, they will pass as "target object" - probably not..
[This message has been edited by Mapraputa Is (edited September 28, 2000).]
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic