Skip to content
Sharp

Core Java · interview question

How would you explain a common pattern for accumulating totals in a loop in an interview?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaloops-and-iteration
Choose one answer
Answer and explanation

Correct answer

A. Initialize outside, accumulate inside

Why

Typically, you initialize the accumulator variable before the loop starts and update it inside the loop to accumulate totals correctly.

Test yourself on Core Java

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

Start free test
All Core Java questions →