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

Discussion

Sample58 is run - what will be the output?

public class Sample58
{
    public static void main(String[] args) throws InterruptedException
    {
        Thread outer = new Thread(() ->
        {
            Thread inner = new Thread(() -> { });
            System.out.println(inner.isDaemon());
        });
        outer.setDaemon(true);
        outer.start();
        outer.join();
    }
}

  • A.An IllegalThreadStateException
  • B.true
  • C.false
  • D.Either value

Answer: B

Daemon status is inherited: a new thread is a daemon exactly when the thread that created it is one. The outer thread was made a daemon before being started, so the thread it creates is a daemon too, without any call to setDaemon.

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

Post your comment

Please log in or register to post a comment.