This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
parameters for Thread constructor (Q46 from Boone�s exam)
Mapraputa Is
Leverager of our synergies
Sheriff
Joined: Aug 26, 2000
Posts: 10065
posted
0
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?
Hi Mapraputa, Can u please give me the link to Boone�s exam. Thx in Advance. Aruna
scott irwin
Ranch Hand
Joined: Aug 07, 2000
Posts: 87
posted
0
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
Sheriff
Joined: Aug 26, 2000
Posts: 10065
posted
0
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
Sheriff
Joined: Aug 26, 2000
Posts: 10065
posted
0
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.
mohit joshi
Ranch Hand
Joined: Sep 23, 2000
Posts: 243
posted
0
Surely you are Joking Mr. the question is abourt the constructor Thread(Runnable target) and not Thread(String name)
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
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
Sheriff
Joined: Aug 26, 2000
Posts: 10065
posted
0
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
Joined: Nov 22, 2008
Posts: 18944
posted
0
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
Jim Goodwin
Greenhorn
Joined: Sep 15, 2000
Posts: 14
posted
0
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.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Mapraputa Is
Leverager of our synergies
Sheriff
Joined: Aug 26, 2000
Posts: 10065
posted
0
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).]