Given the following program, which statements are guaranteed to be true?
public class Main { static Thread makeThread(final String id, boolean daemon) { Thread t = new Thread(id) { public void run() { System.out.println(id);/* w w w . j a va2 s.c o m*/ } }; t.setDaemon(daemon); t.start(); return t; } public static void main(String[] args) { Thread a = makeThread("A", false); Thread b = makeThread("B", true); System.out.print("End\n"); } }
Select the two correct answers.
(a) and (e)
Because the exact behavior of the scheduler is undefined, the text A, B, and End can be printed in any order.
The thread printing B is a daemon thread, which means that the program may terminate before the thread manages to print the letter.
Thread A is not a daemon thread, so the letter A will always be printed.