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

Discussion

Sample08 is run - what will be the output?

public class Sample08
{
    public static void main(String[] args)
    {
        Thread.currentThread().interrupt();
        System.out.print(Thread.interrupted() + " ");
        System.out.print(Thread.interrupted());
    }
}

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

Answer: D

Thread.interrupted() is the static form that tests and clears the status of the current thread. The first call finds the flag set and clears it, so the second finds nothing. That clearing is the whole difference from isInterrupted().

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

Post your comment

Please log in or register to post a comment.