Examveda
Examveda

What is the output for the below code?
class A implements Runnable{
      public void run(){
            System.out.println(Thread.currentThread().getName());
      }
}

public class Test{		
      public static void main(String... args){	
            A a = new A();
       Thread t = new Thread(a);
       t.setName("good");
       t.start();
      }
}

A. good

B. null

C. Compilation fails with an error at line 5

D. Compilation succeed but Runtime Exception

E. None of these

Answer: Option A

Solution(By Examveda Team)

Thread.currentThread().getName() return name of the current thread.


This Question Belongs to Java Program >> Threads

Join The Discussion

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