What will be the result of compiling and running the following program?

class MyRunnable implements Runnable {
    public void run() {
        System.out.println("Runnable!");
    }
}

public class MyThread extends Thread {
    public MyThread() {
        super();
    }

    public MyThread(Runnable target) {
        super(target);
    }

    public void run() {
        System.out.println("Thread!");
    }

    public static void main(String[] args) {
        new MyThread().start();
        new MyThread(new MyRunnable()).start();
    }
}
Explanation
If the method run() is overridden in a Thread class, the overridden method will be called, not method run() of a target Runnable.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes