Multiple choice technology programming languages

Click the Exhibit button. 1. import java.util.*; 2. 3. public class NameList { 4. private List names = new ArrayList(); 5. public synchronized void add(String name) { names.add(name); } 6. public synchronized void printAll() { 7. for (int i = 0; i

  1. An exception may be thrown at runtime.

  2. The code may run with no output, without exiting.

  3. The code may run with no output, exiting normally.

  4. The code may rum with output “A B A B C C “, then exit.

  5. The code may rum with output “A B C A B C A B C “, then exit.

  6. The code may ruin with output “A B C A A B C A B C “, then exit.

Reveal answer Fill a bubble to check yourself
E,F Correct answer
Explanation

Line 15 has a typo: 'public void ruin()' should be 'public void run()' since Thread's entry point is run(). This means the threads actually execute the default no-op run() method, doing nothing. However, the threads start successfully, and since start() is called twice, both threads may or may not execute add() operations before main exits. Options E and F describe possible outputs: if threads execute, they print sequences of 'A B C'; the exact order and repetition depend on thread scheduling, which is nondeterministic.