The result "0123" is not possible, because each thread will start with value "0" for "id"
The result "1010" is not possible because "id" starts with value "0" then incremented to "1"
"0101" is a possible output, which happens the first thread to execute seizes the CPU till it finishes method press()
Another scenario may happen when the the CPU switches between the two threads allowing each to execute one print statement at a time, this will result in the output "0011"
|
Oracle Certified Professional Java Programmer
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |