Which two demonstrate the valid usage of the keyword synchronized?

Which two demonstrate the valid usage of the keyword synchronized?

Which two demonstrate the valid usage of the keyword synchronized?

A.
interface ThreadSafe {
synchronized void doIt();
}

B.
abstract class ThreadSafe {
synchronized abstract void doIt();
}

C.
class ThreadSafe {
synchronized static void soIt () {}
}

D.
enum ThreadSafe {
ONE, TWO, Three;
synchronized final void doIt () {}
}

Explanation:

The Java programming language provides two basic synchronization idioms:
synchronized methods and synchronized statements.
To make a method synchronized, simply add the synchronized keyword to its declaration.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Tim

Tim

The answer is C D.

Tim

Tim

Abstract methods cannot be synchronized.