Ask Question
11 July, 15:49

Recall that the Counter class initializes itself to 0 and allows a client to increment it, and the Increase class is initialized with a Counter c and an int amount and when run, invokes increment on the Counter object c amount times. Identify the possible output of the following code sequence: Counter c = new Counter (); Runnable r = new Increase (c, 2); Thread t = new Thread (r); c. increment (); t. start (); System. out. println (c);

+3
Answers (1)
  1. 11 July, 19:23
    0
    Output can be 0 or 1 or 2.

    Explanation:

    As we are initializing the value with 2 so at most it will increment to 2 times means value will be 2.

    when main thread is printing the c, Increase thread might be started or might not be started

    so output can be 0 or 1 or 2
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Recall that the Counter class initializes itself to 0 and allows a client to increment it, and the Increase class is initialized with a ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers