The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 13:

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