Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these correctly marks a thread as a daemon?

  • A.t.setDaemon(1);
  • B.t.daemon = true;
  • C.Thread.setDaemon(t, true);
  • D.t.setDaemon(true);

Answer: D

setDaemon is an instance method taking a boolean. Java has no conversion from int to boolean, the flag is not an accessible field, and there is no static two-argument form. The call must also come before the thread is started.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.