Menu
Topics Index
...
`

Exception


If you need explanation Read this topic

If you need Answer Take test on this topic

Exception
What will be the output of the following program?
public class Waiting {
    public static void main(String[] args) {
        System.out.print("1 ");
        synchronized (args) {
            System.out.print("2 ");
            try {
                args.wait(); //LINE M
            }
            catch (InterruptedException e) {    System.out.println("4 ");    }
        }
        System.out.print("3 ");
    }
}

A. 1 2 4 3 
B. 1 2 3
C. 1 3
D. 1 2
E. Program execution does not complete
F. Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

E.program execution strucks after printing 12 as args.wait()

Posted by Shabaaz Shaikz    2014-02-25 12:56:34


ans: E because 1,2 printed first....and then args.wait() will be called..so that time we are not passing any parameter into that wait()..so the program is going in to the waiting,,state..sothe next statements are not printed....after that

Posted by Sapparapu Pradeep Kumar    2014-02-25 19:16:40


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-26 04:43:05


© meritcampus 2019

All Rights Reserved.

Open In App