Threads

Q1: What will be the output of the program?
class MyThread extends Thread 
{
    public static void main(String [] args) 
    {
        MyThread t = new MyThread();
        t.start();
        System.out.print('one. ');
        t.start();
        System.out.print('two. ');
    }
    public void run() 
    {
        System.out.print('Thread ');
    }
}

A Compilation fails

B An exception occurs at runtime.

C It prints "Thread one. Thread two."

D The output cannot be determined.

ANS:A - Compilation fails

When the start() method is attempted a second time on a single Thread object, the method will throw an IllegalThreadStateException (you will not need to know this exception name for the exam). Even if the thread has finished running, it is still illegal to call start() again.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.