This is for the first time that I am posting a query. Following are two questions that I had come across in a mock exam, I don’t recollect the location of the exam. Question 1 The programmer can signify through a reference that an object is no longer needed - True/False My Answer I think this statement is both true and false. True part If you want to tell the system that you done with the object, all you have to do is to remove all references to it like this: myObj=null; False part I think the answer is false since an object can have more than one reference. Hence, one reference cannot always determine the fate of an object. Question 2 Which is true about threads? a. If suspended cannot be restarted b. Stop running,if another thread with higher priority is getting runnable. c. Stop running, if the thread starts another thread with the same priority. d. Stop running, if the thread creates another thread. e. If interrupted, stop running. f. If dead cannot be restarted. The answer given is b,c,e,f. What about option (a), calling resume() (although depreciated) on a suspended thread wil put the same in Runnable state. Here if I am not mistaken “restarted” is not a call to start() method, but the Thread in Running state.
For the first question I would say that setting the last reference to an object to null would make that object eligible for garbage collection. That's how I would interpret the question anyway. For the second question: a) is not true because, as you said, the thread can be resumed at a later time. So a) is not an valid answer to the question. The wording of the question is vague, in my opinion b) and c) could better start off with "May stop..." or "Possibly stop..." -Barry
These are not well-worded questions. 99% of the questions on the current 1.4 exam are *not* ambiguous. That said, here's what I think of the answers... Question 2: Ignore anything about suspend/resume. Long gone. The ONLY correct answers are "b" and "f". Answer c and d are false because there's no guarantee about that behavior. But answer e is also false. A thread does NOT necessarily stop running when it is interrupted. In fact, normally the thread that gets "interrupted" is NOT the running thread (although it is possible for a thread to interrupt itself). Normally the running thread sends a signal to another thread by interrupting it, but what the interrupted thread does with that "knowledge" is up to the interrupted thread. Interrupt is just a flag, although some methods (sleep(), wait(), join() can throw interrupted exceptions -- which the thread itself won't even know about until it actually becomes the running thread (although it is likely to become the running thread more quickly if it is interrupted because it will move *out* of a blocked state. So, not only will interrupting a thread NOT stop it from running, but interrupting it is more likely to get it to actually *begin* running again!
Question 1: I agree with your statements. There is no way to know, from this question, if the programmer is holding the *last* reference. So might be true, might be false. You won't have questions like this on the exam. Use of the word "might" "must" "will" etc. are used carefully in the exam. cheers, Kathy