Menu
Question Index
...

What will be the output of the following program?

public class WaitingThread{
    public static void main(String[] args) {
        CounterClass thread1 = new CounterClass(); // LINE A
        thread1.run();
    }
}
class CounterClass extends Thread {
    Thread t = new Thread();
    @Override
    public void run() {
        System.out.println("Thread entered.");
        try {
            t.wait();
        } catch (Exception e) {
            System.out.println("Thread Interrupted.");
        }
        System.out.println("Thread exiting.");
    }
}


Thread entered.
Thread exiting.
Thread entered.
Thread entered.
Thread Interrupted.
Thread exiting.
Output can not determined
Compilation Error or Runitme Error

Doubts

Problems

Topic: Java Inter Thread Communication With Example

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App