MCQ: Which of the following is a mutable class in java?

Which of the following is a mutable class in java?

  1. java.lang.String
  2. java.lang.Byte
  3. java.lang.Short
  4. java.lang.StringBuilder

Answer

d. java.lang.StringBuilder

Explanation:

A mutable class is a class in which changes can be made after its creation. We can modify the internal state and fields of a mutable class. The StringBuilder class is a mutable class, as it can be altered after it is created.

The String, Byte, and Short are immutable classes as they cannot be altered once they are created.

Hence, the correct answer is an option (d).


Comments