Question 25
|
Multiple objects of MyClass (given below) are used in a program that uses multiple Threads to create new integer count. What will happen when other threads use the following code? class MyClass { static private int myCount = 0; int yourNumber; private static synchronized int nextCount() { return ++myCount; }
public void getYourNumber() { yourNumber = nextCount(); } }
|
||
| The code will give compilation error. | ||
| The code will give runtime error. | ||
| Each thread will get a unique number. | ||
| The uniqueness of the number among different Threads can't be guaranteed. | ||
Back to beginning | Next Question |
||
