Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
hard

Static Method Hiding and Synchronization

Mark
< Prev
Next >

Consider the following code. Which statement best describes the potential concurrency issue that arises from the log method in the StaticDerived class?

class StaticBase {
    public static synchronized void log(String msg) {
        System.out.println("Base log: " + msg);
    }
}

class StaticDerived extends StaticBase {
    public static void log(String msg) {
        // Hidden method without synchronization
        System.out.println("Derived log: " + msg);
    }
}

public class StaticOverrideTest extends Thread {
    public void run() {
        StaticDerived.log("Message");
    }
    
    public static void main(String[] args) {
        Thread t1 = new StaticOverrideTest();
        Thread t2 = new StaticOverrideTest();
        t1.start();
        t2.start();
    }
}
A

A compile-time error will occur because synchronization cannot be removed in a subclass.

B

There is no issue because static methods cannot be overridden.

C

Deadlock is inevitable because static methods must always synchronize on the class object.

D

The static method in StaticDerived is not synchronized, risking race conditions when invoked concurrently.

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|