-
Assertion (A): The String
class in Java is immutable.
- True. In Java, once a
String
object is created, it cannot be changed. Any modification to a String
object results in the creation of a new String
object.
-
Reason (R): Immutable objects cannot be modified once they are created, and any operation on a String
object results in the creation of a new String
object.
- True. This is a correct explanation of immutability. Since
String
objects are immutable, any operation that appears to modify a String
actually creates a new String
object.
Correct Answer:
a) Both Assertion(A) and Reason(R) are true and Reason(R) is correct explanation of Assertion(A).