This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The synchronized statement has the form shown above. Which of the following are true statements?
a. A compile-time error occurs if the expression produces a value of any reference type b. A compile-time error occurs if the expression produces a value of any primitive type c. A compile-time error does not occur if the expression is of type boolean d. The sychronized block may be processed normally if the expression is null e. If execution of the block completes normally, then the lock is released f. If execution of the block completes abruptly, then the lock is released g. A thread can hold more than one lock at a time h. Synchronized statements can be nested i. Synchronized statements with identical expressions can be nested
given answer is :b,e,f,g,h,i
i didnt get the question can anyone explain the above one(explain for each option)
Option b : (A compile-time error occurs if the expression produces a value of any primitive type) Synchronized block will only accept objects not primitives.
Option e & Option f If execution of the block completes normally (or) abruptly, then the lock is released) After synchronized block is executed, Object lock acquired by the thread before executing this block is released; it doesn't matter whether thread exits the block normally or abnormally.
Option g A thread can hold more than one lock at a time) Thread executing the below synchronized block(block A) will acquire two locks.(object1, object2).