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

Discussion

Sample12 is run - what will be the output?

public class Sample12
{
    public static void main(String[] args)
    {
        System.out.println(Thread.currentThread().getName());
    }
}

  • A.Thread-0
  • B.Sample12
  • C.An empty line
  • D.main

Answer: D

The thread the JVM creates to run main is named main, and currentThread() returns whichever thread is executing the call. Thread-0 is the default name given to the first Thread object a program constructs, which this program never does.

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

Post your comment

Please log in or register to post a comment.