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

Discussion

Sample13 is run - what will be the output?

public class Sample13
{
    public static void main(String[] args)
    {
        Thread a = new Thread();
        Thread b = new Thread();
        System.out.println(a.getName() + " " + b.getName());
    }
}

  • A.Thread-0 Thread-1
  • B.Thread-1 Thread-2
  • C.main main
  • D.Two empty names separated by a space

Answer: A

A thread constructed without a name is given one by appending a counter that starts at zero, so the first two are Thread-0 and Thread-1. Neither is started here, which does not matter: the name is assigned by the constructor.

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

Post your comment

Please log in or register to post a comment.