Java OCA OCP Practice Question 879

Question

Which are true statements? (Choose all that apply)

  • A. An immutable object can be modified.
  • B. An immutable object cannot be modified.
  • C. An immutable object can be garbage collected.
  • D. An immutable object cannot be garbage collected.
  • E. String is immutable.
  • F. StringBuffer is immutable.
  • G. StringBuilder is immutable.


B, C, E.

Note

Immutable means the state of an object cannot change once it is created.

Immutable objects can be garbage collected just like mutable objects.

String is immutable.

StringBuilder can be mutated with methods like append().

Although StringBuffer isn't on the exam, you should know about it anyway in case older questions haven't been removed.




PreviousNext

Related