ProgrammingEasyTCS NQT · Infosys pattern

Which statement about Java String objects is correct?

  1. A. They are primitive types
  2. B. They are immutable: methods like toUpperCase return a new String
  3. C. They are mutable but thread-unsafe
  4. D. They can be changed in place with setCharAt

Correct answer: B. They are immutable: methods like toUpperCase return a new String

A String's characters never change after creation; every modifying-looking method returns a new object. setCharAt belongs to StringBuilder, the mutable alternative.

More OOP with C++ and Java questions

Exams that ask this topic