This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hi all, Question 2 Which of the following are true? a. A program will terminate only when all daemon threads stop running. b. A program will terminate only when all user threads stop running. c. A daemon thread always runs at Thread.MIN_PRIORITY. d. A thread inherits its daemon status from the thread that created it. e. The daemon status of a thread can be changed at any time using the Thread.setDaemon method. f. The Thread.setDaemon method accepts one of two argument values defined by the constants Thread.DAEMON and Thread.USER. g. None of the above. Answer is (b) & (d) Its right that a thread created from daemon thread is always a daemon thread. The option (d) cannot be generalized to create daemon threads, as a thread obtained from non-daemon thread can be made to work as daemon thread using setDaemon(true). So how can we consider the option (d) as fully correct. Plz help me with this, i am always confused with such multiple choice questions.. Thanks reshma
concerning multiple choice questions, all i can say is, i am thankful they are going to give me options of how many answers to provide in the real exam! i think the key to answer (d) is in the wording - specifically the first word... "A"; not "All"". d. A thread inherits its daemon status from the thread that created it. as you say, not all daemon threads are created from daemon threads. i guess it would have been obviously INcorrect if it was worded such as- d. All daemon threads inherit their daemon status from the daemon threads that created them. but as it stands, it can be seen as correct.
I don't see any ambiguity in d option. It is right that when a thread is created from daemon thread you get deamon status. If you create a thread from user thread then you get user thread. It is not saying that it is the final status and you can't change it. No. You can chage the thread from daemon to user or vice versa before starting the thread. It is only talking about what you get immidiately after creation from parent thread before executing next line. May be in the very next line you change the thread to user. But it is a different story.
As Sarma stated above, each new thread inherits the daemon status of the thread that created the new thread. Before the new thread is started, the daemon status can be changed using the setDaemon method.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>