Skip to content
Sharp

Engineering Interviews · interview question

How does Java ensure that String objects are immutable?

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

Correct answer

A. By not providing any methods to modify the contents.

Why

Java's String class does not provide any methods to change the value of an existing String object. Instead, any modification results in a new String object, preserving immutability.

Test yourself on Engineering Interviews

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

Start free test
All Engineering Interviews questions →