I understood the explanation but for the exam point of view , what are we going to do if such type of question comes in paper. I mean if a thread does not do notify and the other thread calls wait on that thread object ( as i have posted earlier), so are we going to acknowledge the implementation detail fact about Thread ( according to which it calls notifyall implicitly once it completes). If we acknowledge this fact then the behavior of such a the code if asked in exam would not be a thread waiting forever and git simply gives the output. On the other hand if we do not acknowledge it then then we should say that the thread will wait for ever as there is no notify. Please clarify what to do in exam ?? I am confused because Henry wrote earlier that:
This is an implementation detail, and can't be dependent to behave this way with all JVMs.
As Deepak said, that the answer would be that the wait call will wait forever in the second code (from exam point of view). But the specific examples that you gave in that other topic, both the codes might keep waiting forever.
In this code, the run method might get the lock over ThreadB object before the main method, so the call to wait in the main method might never return. Same is with the second code. So for the first code, the output is unpredictable (output can be 45 or the program could wait forever) and for the second code, the output is that the program will wait forever...