Computer Applications

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.

  1. (A) is true and (R) is false.
  2. (A) is false and (R) is true.
  3. Both (A) and (R) are true and (R) is a correct explanation of (A).
  4. Both (A) and (R) are true and (R) is not a correct explanation of (A).

Java String Handling

3 Likes

Answer

(A) is false and (R) is true.

Reason — In Java, Strings are immutable, so the substring() method does not modify the original String, it returns a new String, making Assertion (A) false. However, the method does extract a part of the String starting from a specific index, which makes Reason (R) true.

Answered By

1 Like


Related Questions