Examveda
Examveda

What is the output for the below code?
public class Test extends Thread{
      public static void main(String argv[]){
            Test t = new Test();
            t.run();
      }

      public void start(){
            for(int i = 0; i < 10; i++){
                  System.out.println("Value of i = " + i);
            }
      }
}

A. A compile time error indicating that no run method is defined for the Thread class

B. A run time error indicating that no run method is defined for the Thread class

C. Clean compile and at run time the values 0 to 9 are printed out

D. Clean compile but no output at runtime

E. None of these

Answer: Option D


This Question Belongs to Java Program >> Threads

Join The Discussion

Comments ( 1 )

  1. GUNJAN BARHAIYA
    GUNJAN BARHAIYA :
    6 years ago

    It Is Option D
    not A and B because run is already defined in thread which is already extended
    Not c because start() not called.

Related Questions on Threads

What is a thread in Java?

A. A lightweight process that runs independently within a program

B. A data structure to store variables

C. A type of loop

D. A synchronization mechanism