Which statement about Java String objects is true?

2025

Which statement about Java String objects is true?

Answer: C. Once a String object is created, its contents cannot be changed.ConceptAn immutable object keeps the same observable state after construction. Java String represents a fixed character sequence; operations that appear to…

  1. A.

    String is implemented as a primitive data type.

  2. B.

    A String object must be explicitly destroyed when it is no longer in use.

  3. C.

    Once a String object is created, its contents cannot be changed.

  4. D.

    A String object can be copied by using the == operator.

Attempted by 219 students.

Show answer & explanation

Correct answer: C

Concept

An immutable object keeps the same observable state after construction. Java String represents a fixed character sequence; operations that appear to modify a String create and return a different String.

Application

Consider String s = "gate"; then String t = s.concat("way").

  1. s refers to the String value "gate".

  2. concat creates a new String value "gateway", and t refers to that new object.

  3. s still refers to "gate"; the contents of the original String object were not changed.

Cross-check and contrast

  • String is a class, not a primitive type.

  • An unreachable String object becomes eligible for garbage collection; Java code does not explicitly destroy it, and collection timing is not guaranteed.

  • The == operator compares references for String operands; it does not copy a String.

Therefore, once a String object is created, its contents cannot be changed.

Explore the full course: Up Lt Grade Assistant Teacher 2025

Loading lesson…