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? 

package my; import java.util.*; public class ThreadSafeList { } private List data

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

1 Expert Approved Answer
Step: 1 Unlock

The provided image shows a Java class named ThreadSafeList with methods to add values get values at ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Oracle Questions!