Hi,
This is the question on Threads from Dan's site:
class A extends
Thread {
public void run() {
synchronized (this) {
try{wait();} catch (InterruptedException ie){}
}
}
public static void main(
String[] args) {
A a1 = new A();
long startTime = System.currentTimeMillis();
a1.start();
System.out.print(System.currentTimeMillis() - startTime + ",");
}
}
What are the possible results of attempting to compile and run the program?
a. The number printed is greater than or equal to 0.
b. The synchronized block inside the run method is not necessary.
c. This program runs to completion after the elapsed time is printed.
d. Compiler error.
e. Run time error.
f. None of the above.
Answer is : a
But could one of the outcomes not be (f)- None of the above becuase what is the a1.start() call starts the thread a1 first and does not reach print statement. Is it not possible?
Thanks,
Sumeer.