Q: Assertion(A): The String class in Java is immutable.
Reason(R): Immutable object can not be modified once they are created and any operation on a String object results in the creating of a new String object.
-
A
Both Assertion(A) and Reason(R) are true and Reason(R) is correct explanation of Assertion(A).
-
B
Both Assertion(A) and Reason(R) are true and Reason(R) is not correct explanation of Assertion(A).
-
C
Assertion(A) is true and Reason(R) is false.
-
D
Assertion(A) is false and Reason(R) is true.
A
Answer:
A
Explanation:
-
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).
Related Topic:
Share Above MCQ