Review Questions

9.5 Given the following program, which statements are guaranteed to be true?
public class ThreadedPrint {
    static Thread makeThread(final String id, boolean daemon) {
        Thread t = new Thread(id) {
            public void run() {
                System.out.println(id);
            }
        };
        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.

  1. The letter A is always printed.

  2. The letter B is always printed.

  3. The letter A is never printed after End.

  4. The letter B is never printed after End.

  5. The program might print B, End ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.