Advertisements
Advertisements
Question
Assertion (A): The substring() method modifies the original String.
Reason (R): The substring() method can extract part of a String starting from a specific index.
Options
(A) is true and (R) is false.
(A) is false and (R) is true.
Both (A) and (R) are true and (R) is the correct explanation of (A).
Both (A) and (R) are true, but (R) is not the correct explanation of (A).
MCQ
Assertion and Reasoning
Advertisements
Solution
(A) is false and (R) is true.
Explanation:
- (A) is false: String objects are immutable in Java, so the original string cannot be changed.
- (R) is true: The method can be used as
substring(beginIndex)orsubstring(beginIndex, endIndex)to extract a specific portion of a string.
shaalaa.com
Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
