Hi,
I got a question about
Thread #4 Question 9.
==========================================
class A extends Thread {
public void run() {
System.out.print("A");
}
}
class B {
public static void main (
String[] args) {
A a = new A();
a.start();
try {
a.join();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
a.start(); // 1
}
}
What is the result of attempting to compile and run the program?
a. The program compiles and runs without error.
b. The second attempt to start thread t1 is successful.
c. The second attempt to start thread t1 is ignored.
d. Compiler error at marker 1.
e. An IllegalThreadStateException is thrown at run-time.
f. None of the above
======================================
Dan's answer for this output was
e. "An IllegalThreadStateException is thrown at run-time."
Dan's explanation told us that we should know the actual behavior of 1.4 version of the JVM.
If in the reality, the original thread has been dead by a.join() and line 1 has been ignored, I thought that this would be the actual behavior of the JVM (I tried it and it didn't throw any exception -- compiled fine and printed "A").
Yes, I am aware of the fact that if there is no join() method, IllegalThreadStateException will be thrown.
Is there any way to theorize that the answer "can" be "a" and possibly "c"? I'm curious. Thank you very much for your help.
Emiko