Skip to content
Sharp

Engineering Interviews · interview question

Which Java feature ensures that a variable is visible across threads immediately after being updated?

Multiple choiceMediumchapter-20-curatedpremiumengineering-interviewsjvm-trivia
Choose one answer
Answer and explanation

Correct answer

A. Volatile keyword

Why

The volatile keyword in Java ensures that a variable's updates are immediately visible to all threads. This prevents threads from caching variables locally, thus maintaining a consistent shared state across multiple threads.

Test yourself on Engineering Interviews

A free test with instant, explained results. No account needed.

Start free test
All Engineering Interviews questions →