Consider the following program and choose a right option:
class MyThread extends Thread { public void run(){ System.out.println("Running"); }/*from ww w .j a va 2s . com*/ public static void main(String args[]) throws InterruptedException { Runnable r = new MyThread(); //#1 Thread myThread = new Thread(r); //#2 myThread.start(); } }
c)
The class Thread implements the Runnable interface, so the assignment in statement #1 is valid.
Also, you can create a new thread object by passing a Runnable reference to a Thread constructor, so statement #2 is also valid.
Hence, the program will compile without errors and print "Running" in the console.