Facebook

adsense

Tuesday, 28 April 2015

QUESTION 9

What will happen when you attempt to compile and run the following code?

class MyThread extends Thread
{
    public void run()
    {
        System.out.println("MyThread: run()");
    }
    public void start()
    {
        System.out.println("MyThread: start()");
    }
}
class MyRunnable implements Runnable
{
    public void run()
    {
        System.out.println("MyRunnable: run()");
    }
    public void start()
    {
        System.out.println("MyRunnable: start()");
    }
}
public class MyTest 
{
    public static void main(String args[])
    {
        MyThread myThread  =  new MyThread();
        MyRunnable myRunnable = new MyRunnable();
        Thread thread  =  new Thread(myRunnable);
        myThread.start();
        thread.start();
    }
}
--------------------------------------------------------------------------
A. Prints : MyThread: start() followed by MyRunnable:run()
B. Prints : MyThread: run() followed by MyRunnable:start() 
C. Prints : MyThread: start() followed by MyRunnable:start() 
D. Prints : MyThread: run() followed by MyRunnable:run() 
E. Compile time error 
F. None of the above

                   <PREVIOUS || Main Page || NEXT >
    Give your answers in the comment below

No comments:

Post a Comment