?
What will happen after compiling and running following code?
What will happen after compiling and running following code?
class A implements Runnable{
public void run(){
System.out.println("run-a");
}
}
public class Test{
public static void main(String... args){
A a = new A();
Thread t = new Thread(a);
t.start();
t.start();
}
}
class A implements Runnable{
public void run(){
System.out.println("run-a");
}
}
public class Test{
public static void main(String... args){
A a = new A();
Thread t = new Thread(a);
t.start();
t.start();
}
}
Answer & Solution
Correct Answer:
Option
D
Once a thread has been started, it can never be started again. 2nd time t.start() throws java.lang.IllegalThreadStateException.
Join the Discussion
Login to post a comment or share your explanation.
Login