This code doesn't compile. Answer A means the code would throw InterruptedException while running. Your code has a compile error where obj.wait can throw InterruptedException and the exception isn't handled and the method is not declared as throwing it, so the class can't compile. So Answer A is not applicable here.
Of course the code from the question has the same problem. So the question seems flawed.
Once you fix the compile error, and move the waitForSignal call into the Thread's run method so that it gets called by the sd thread instead of the main thread,
you should have something like:
public class ThreadStateProblem extends Thread {
public void run() {
waitForSignal();
}
void waitForSignal() {
Object obj = new Object();
synchronized (Thread.currentThread()) {
try {
obj.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
obj.notify();
}
}
public static void main(
String []s) {
ThreadStateProblem sd =new ThreadStateProblem();
sd.start();
}
}
then you should get the expected result:
Exception in thread "Thread-0" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:503)
at ThreadStateProblem.waitForSignal(ThreadStateProblem.java:10)
at ThreadStateProblem.run(ThreadStateProblem.java:3)