Skip to content
Sharp

Core Java · interview question

Which practice is the safest default for managing variable scope inside methods when calculating the shipping cost?

Multiple choiceMediumchapter-1-curatedpremiumcore-javascope-and-reassignment
Choose one answer
Answer and explanation

Correct answer

C. Use the smallest scope possible for each variable.

Why

Using the smallest scope possible for each variable limits potential errors and side-effects, making the code more maintainable and easier to understand.

Test yourself on Core Java

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

Start free test
All Core Java questions →