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

Discussion

Sample57 is run - what will be the output?

public class Sample57
{
    public static void main(String[] args)
    {
        System.out.print(Thread.currentThread().isDaemon() + " ");
        System.out.print(new Thread().isDaemon());
    }
}

  • A.false false
  • B.false true
  • C.true false
  • D.true true

Answer: A

Correct answer: false false

The main thread is created by the JVM as a user thread, so the first call prints false. A newly constructed thread inherits its daemon status from the thread that created it, and here that is main - so the second prints false as well. The status is inherited at construction and can be changed with setDaemon, but only 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.