Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
hard Solved by 1 students

Concurrency With Overloaded Methods

Mark
< Prev
Next >

Consider the OverloadArray class provided below. Which statement best describes a potential concurrency issue arising from the overloaded updateScores methods?

public class OverloadArray {
    private int[] scores = {10, 20, 30};
    
    public synchronized void updateScores() {
        scores[0] += 5;
        scores[1] += 5;
    }
    
    public void updateScores(int index) {
        scores[index] += 10;
    }
    
    public static void main(String[] args) {
        OverloadArray oa = new OverloadArray();
        Thread t1 = new Thread(() -> oa.updateScores());
        Thread t2 = new Thread(() -> oa.updateScores(2));
        t1.start();
        t2.start();
    }
}
A

Method overloading is disallowed in multithreaded contexts, which is the root cause of the problem.

B

Since the unsynchronized method only updates scores[2], it is isolated and does not affect the overall thread safety.

C

The overloaded updateScores(int) method is not synchronized, so its concurrent call with the synchronized updateScores() may result in unsynchronized access to the scores array.

D

Overloading methods automatically makes them both synchronized, thereby preventing any concurrency issues.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|