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

Discussion

Sample09 is run - what will be the output?

public class Sample09
{
    static void report()
    {
        System.out.print(Thread.currentThread().isInterrupted() + " ");
    }

    public static void main(String[] args)
    {
        Thread.currentThread().interrupt();
        report();
        report();
    }
}

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

Answer: A

isInterrupted() reports the status without changing it, so both calls answer true and the flag is still set afterwards. Swapping it for the static Thread.interrupted() would give true then false, which is the trap this pair of questions exists to separate.

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

Post your comment

Please log in or register to post a comment.