Question: Which statement about the following class is correct? A. The code compiles and is thread-safe. B. The code compiles and is not thread-safe. C. The
Which statement about the following class is correct?

A. The code compiles and is thread-safe.
B. The code compiles and is not thread-safe.
C. The code does not compile because of the size() method.
D. The code does not compile because of the getValue() method.
E. The code does not compile for another reason.
F. None of the above.
package my; import java.util.*; public class ThreadSafeList { } private List data = new ArrayList (); public synchronized void addValue(int value) { data.add (value); } public int getValue(int index) { return data.get (index); } public int size () { synchronized (ThreadSafeList.class) { return data.size(); } }
Step by Step Solution
3.23 Rating (150 Votes )
There are 3 Steps involved in it
The provided image shows a Java class named ThreadSafeList with methods to add values get values at ... View full answer
Get step-by-step solutions from verified subject matter experts
