Multiple choice technology programming languages

What will be the output of the following program? package scjp.threadTest; public class Ques01 { public static void main(String[] args) { HelloThread hello = new HelloThread(); hello.start(); } } class MyThread implements Runnable{ @Override public void run() { System.out.println("My thread"); } } class HelloThread extends Thread{ public void start(){ System.out.println("Hello thread"); } public void run(){ Thread thread = new Thread(new MyThread()); thread.start(); } }

  1. The program will output 'Hello Thread' and 'My Thread'.

  2. The program will output 'Hello Thread'.

  3. The program will output 'My Thread' and 'Hello Thread'.

  4. The order of the outputs is not will vary upon execution.

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

HelloThread overrides start() without calling super.start(). When main() calls hello.start(), the overridden method prints 'Hello thread' and returns - no actual thread is created. The run() method (which would create and start a new MyThread) is never invoked because the Thread lifecycle never begins. Output is just 'Hello thread' once.