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.
The correct answers are C and D
C D
Illegal modifier for the interface method doIt; only public & abstract are permitted.
The abstract method doIt in type thread can only set a visibility modifier, one of public or protected.
C and D
C D
c,d