Interview Questions

Output question 12.

Java Interview Questions and Answers (part 4)


(Continued from previous question...)

72. Output question 12.

public class MyClass {

public static void main(String[] args) throws InterruptedException {

synchronized (args) {
System.out.print("1 ");
args.wait();
System.out.print("2 ");
}

}
}



Answer.
Though this question looks bit similar to output question 4 but intention is to show args is object and we can acquire lock on it.

Thread acquires lock on args object but notify wasn't called so 2 will never be printed, this is called frozen process.


/*OUTPUT
1
*/

(Continued on next question...)

Other Interview Questions