Menu
Question Index
...

What will be the output of the following program?

public class Watch {
    static final StringBuffer sb1 = new StringBuffer();
    static final StringBuffer sb2 = new StringBuffer();
    public static void main(String args[]) {
        new Thread() {
            public void run() {
                synchronized (sb1) {
                    sb1.append("A");
                    sb2.append("B");
                }
            }
        }.start();
        new Thread() {
            public void run() {
                synchronized (sb1) {
                    sb1.append("C");
                    sb2.append("D");
                }
            }
        }.start();
        System.out.println("Output : " + sb1 + " " + sb2);
    }
}


Output : C D
Output : A B
Output : A BD
Output : AC D
Output : AC BD
Compilation Error or Runtime Error

Doubts

Problems

Topic: What is Multitasking and Multithreading?

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App