Ask 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 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);

+2
Answers (1)
  1. 27 May, 11:34
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers