MCQ Single Best Answer Not Set

QAnalyze the following code:
public class Test implements Runnable{
        public static void main(String[] args){
                Test t = new Test();
        }

        public Test(){
                Thread t = new Thread(this);
                t.start();
        }

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

ID: #2299 Java thread MCQ 1,089 views
Question Info
#2299Q ID
Not SetDifficulty
Java thread MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A The program has a compilation error because t is defined in both the main() method and the constructor Test().
  • B The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.
  • C The program compiles and runs and displays nothing.
  • D The program compiles and runs and displays test.
Correct Answer: Option D

Explanation

The program compiles and runs and displays test.

Share This Question

Challenge a friend or share with your study group.