Question:

Assertion and Reasoning

Assertion (A): The substring() method modifies the original String.

Reason (R): The substring() method can extract part of a String from a specific index.

Show Hint

In Java, Strings are immutable. Methods like \texttt{substring()}, \texttt{concat()}, and \texttt{replace()} return new Strings instead of changing the original one.
  • (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).
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understand the Assertion.
The assertion says that the \texttt{substring()} method modifies the original String. In Java, Strings are immutable, which means once a String is created, its original content cannot be changed. Any method like \texttt{substring()} does not alter the original String. Instead, it returns a new String containing the required part. Therefore, the Assertion is false.
Step 2: Understand the Reason.
The reason says that the \texttt{substring()} method can extract part of a String from a specific index. This statement is correct. For example, if we write: \[ \texttt{"COMPUTER".substring(3)} \] it returns the part of the String starting from index 3 till the end. So, the Reason is true.
Step 3: Check the relation between Assertion and Reason.
Although the Reason is true, it does not support the Assertion. The method \texttt{substring()} only extracts a part of the String and returns it as a new String. It does not modify the original String. Hence, the Assertion is false, while the Reason is true.
Step 4: Conclusion.
So, the correct option is: \[ (B) (A) is false and (R) is true \] because \texttt{substring()} extracts part of a String, but it does not change the original String.
Final Answer:(A) is false and (R) is true.
Was this answer helpful?
0
0

Questions Asked in ICSE Class X board exam

View More Questions