Welcome Guest | Sign in | Register
Threads - Discussion Page For Q.2950 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Threads > Questions and Answers

Q: What is the output for the below code ?

class A implements Runnable{
public void run(){
System.out.println("run-a");
}
}
1. public class Test {
2. public static void main(String... args) {
3. A a = new A();
4. Thread t = new Thread(a);
5. t.start();
6. t.start();
7. }
8. }
A. run-a B. run-a run-a
C. Compilation fails with an error at line 6 D. Compilation succeed but Runtime Exception

Answer and Explanation

Answer:Compilation succeed but Runtime Exception

Explanation:
Once a thread has been started, it can never be started again. 2nd time t.start() throws
java.lang.IllegalThreadStateException.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.