Skip to content
CodeKruPro

What does volatile guarantee?

QuizMediumJava onlyAsked in: Accenture

A volatile boolean running flag (volatile is a keyword that controls how threads see a field) is set to false by one thread to stop a loop in another. Which statements are true? Pick all that apply.

  • volatile guarantees the loop thread sees the new value
  • volatile makes counter++ on a volatile int safe
  • Without volatile (or another form of synchronisation), the loop might never see the change

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in