Menu
Topics Index
...
`

Threads1920


If you need explanation Read this topic

If you need Answer Take test on this topic

Threads1920
What will be the output of the following program?
public class OwnClass {
    public static void main(String args[]) {
        OwnClass oc = new OwnClass();
        oc.method1();
    }
    public void method1() {
        ThreadAsc trd = new ThreadAsc("OneThread");
        trd.start();
    }
}
class ThreadAsc extends Thread {
    private String str1 = " ";
    ThreadAsc(String s) {
        str1 = s;
    }
    public void run() {
        methodWait();
        System.out.println("Thread Completed");
    }
    public void methodWait() {
        while (true || false | false | true) {
            try {
                System.out.println("Waiting Thread");
                wait();
            } catch (InterruptedException e) {
                System.out.println("Exception");
            }
            System.out.println(str1);
        }
    }
}

A. OneThread
Waiting Thread
Thread Completed
B. Thread Completed
C. Waiting Thread
Exception
D. Waiting Thread
Thread Completed
E. Output can not be determined
F. Compilation Error or Runtime Error
Topic: What is Multitasking and Multithreading?

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.

ans f.runtime err ,it prints waiting thread aft tat wait() and methodwait throws an exception.
illegalmonitorStateException.

Posted by Maheshwari Natarajan    2014-06-10 14:22:40


ans c

Posted by Adithya Aleti    2014-06-10 14:57:18


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

Posted by Merit Campus    2014-06-11 04:01:00


© meritcampus 2019

All Rights Reserved.

Open In App