Home » Java Programming » Java.lang Class

What will be the output of the program? public class Test { public static void main(String[] args) { final StringBuffer a = new StringBuffer(); final StringBuffer b = new StringBuffer(); new Thread() { public void run() { System.out.print(a.append("A")); synchronized(b) { System.out.print(b.append("B")); } } }.start(); new Thread() { public void run() { System.out.print(b.append("C")); synchronized(a) { System.out.print(a.append("D")); } } }.start(); } }

Correct Answer: Indeterminate output

Explanation:

It gives different output while executing the same compiled code at different times.

← Previous Question Next Question→

More Questions from Java.lang Class

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion