The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 14:

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();
A. The code will give compilation error.
B. The code will give runtime error.
C. Each thread will get a unique number.
D. The uniqueness of the number among different Threads can't be guaranteed.