Selection 3 is:Which of the following statements are true?
... you are saying that this is not true. Your explanation is:synchronized keyword may be applied to a non-primitive variable.
Consider this code:It can only be applied to a method or a block.
Code: Select all
public class WaitTest {
public static void main(String[] args) {
System.out.print("1 ");
synchronized(args){
System.out.print("2 ");
try {
args.wait();
}
catch(InterruptedException e){}
}
System.out.print("3 ");
}
}
Isn't args considered a non-primitive variable (an array object) and, if so, doesn't the code synchronize on that non-primitive variable? Please help me understand your position.
Thank you.