in JAVA by
Q:
Which of the following modifiers can be used for a variable so that it can be accessed by any thread or a part of a program?

a) global

b) transient

c) volatile

d) default

1 Answer

0 votes
by

(c) volatile

Reason: In Java, we can modify the values of a variable with the help of a reserved keyword known as volatile. It is a different way of making a class thread-safe. Thread-safe means that the methods and objects of a class are accessible by multiple threads at the same time.

The volatile keyword is not a replacement of a synchronized block or method as it does not remove the need for synchronization among the atomic actions.

Global is not a reserved keyword in Java. The transient and default are keywords in Java, but they are not used for accessing a variable by a thread from any part of the program.

Related questions

0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
...