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

Discussion

Which of these statements about how many threads a Java program starts with is correct?

  • A.A Java program starts with no threads until the first Thread object is created.
  • B.A Java program starts with two threads, one for main and one for the garbage collector only.
  • C.A Java program starts with one thread per class that is loaded.
  • D.A Java program starts with one thread already running, the one executing main.

Answer: D

The JVM creates a thread to run main, so single-threaded code is really one-thread code. That thread is not a daemon, which is why the program does not exit while it is still running, and it is the thread whose name Thread.currentThread().getName() reports as main.

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

Post your comment

Please log in or register to post a comment.