Please excuse me if this question has been discussed. tried doin a search but then cudnt help myself!
QUESTION : 27
Read the following snippet carefully
1. public synchronized void someMethod() {
2. //lots of code
3. try {
4. Thread.sleep(500);
5. } catch(InterruptedException e) {
6. //do some things here.
7. }
8. //more and more code here
9. }
Select all correct answers
a) code causes compilation error -sleep cannot be called in synchronised methods
b)
thread sleeps for atleast 500 ms in this method if not interrupted
c) When the thread goes to sleep it releases lock on the object.
d) the sleeping thread alwayz have lock on the object.
ans given c,d
according to me it shud have been only b)
but then went thru khalid and it says c is right too
but how d) can be possible if c is true?
Please help
arv