Menu
Question Index
...

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);
        }
    }
}


OneThread
Waiting Thread
Thread Completed
Thread Completed
Waiting Thread
Exception
Waiting Thread
Thread Completed
Output can not be determined
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