Java OCA OCP Practice Question 72

Question

Which of the following lines of output are displayed by the following program?

public class Main {
   public static void main(String args[]) {
      MyThread t = new MyThread();
      t.displayOutput("t has been created.");
      t.start();// w w  w .j  a  v  a  2  s  . c o  m
   }
}

class MyThread extends Thread {
   public void displayOutput(String s) {
      System.out.println(s);
   }

   public void run() {
      displayOutput("t is running.");
   }

}
  • A. t has been created.
  • B. t is running.
  • C. The program will display different output.
  • D. None of the above. The program does not compile.


A and B.

Note

Both A and B are displayed.




PreviousNext

Related