🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.MT
  2. B.M
  3. C.It changes from run to run
  4. 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 →