Multiple choice

public class MyRunnable implements Runnable 
{
    public void run() 
    {
        // some code here
    }
}

Which of these will create and start this thread?

  1. new Runnable(MyRunnable).start();

  2. new Thread(MyRunnable).run();

  3. new Thread(new MyRunnable()).start();

  4. new MyRunnable().start();

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Because the class implements Runnable, an instance of it has to be passed to theThread constructor, and then the instance of the Thread has to be started. 1 is incorrect. There is no constructor like this for Runnable because Runnable is an interface, and it is illegal to pass a class or interface name to any constructor. 2 is incorrect for the same reason; you can't pass a class or interface name to any constructor. 4 is incorrect because MyRunnable doesn't have a start() method, and the onlystart() method that can start a thread of execution is the start() in the Threadclass.