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(); }}

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(); }}
Correct Answer good

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

Related Questions

Analyze 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"); } }
What will be the output of the following program code? public class Test implements Runnable{ public static void main(String[] args){ Thread t = new Thread(this); t.start(); } public void run(){ System.out.println("test"); } }