← Quiz: Java Multithreading: all 10 questions
Quiz: Java Multithreading · Question 10 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) throws InterruptedException {
StringBuffer sb = new StringBuffer();
Thread t = new Thread(() -> sb.append("T"));
t.start();
t.join();
sb.append("M");
System.out.println(sb);
}
}
- A.MT
- B.M
- C.It changes from run to run
- D.TM
Answer & explanation
Correct answer: TM
join() makes main wait until thread t has finished, so "T" is always appended before "M".
Can you get the rest right without peeking?
Take the timed Quiz: Java Multithreading quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →