Java OCA OCP Practice Question 2664

Question

Consider the following program and predict the output:

class MyThread extends Thread {
        public void run() {
                try {
                        this.join();
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }//from  w  w w.ja v  a2  s. c o m
                System.out.println("In run method; thread name is: " + Thread.
                currentThread().getName());
        }
        public static void main(String args[])  {
                Thread myThread = new MyThread();
                myThread.start();
        }
}
  • a) The program results in compiler error(s).
  • b) The program results in throwing an IllegalThreadStateException.
  • c) The program prints the following: In the run method; thread name is: thread-0
  • d) The program will never terminate.


d)

Note

Calling this.join() will result in indefinite waiting since the thread is waiting for the thread itself to terminate.




PreviousNext

Related