1. Home
  2. Computing & Technology
  3. Computer Certification

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



Explore Computer Certification
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Computer Certification

©2009 About.com, a part of The New York Times Company.

All rights reserved.