Multiple choice general knowledge

How do substring() and substr() differ?

  1. One is not a method of the String object.

  2. substr() takes three arguments, substring() only two.

  3. Only one accepts a desired string length as an argument.

  4. Besides the spelling, nothing

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

substr() accepts a start position and length parameter, while substring() takes start and end positions. Only substr() allows specifying the desired string length directly. Option A is incorrect because both are String methods. Option B is wrong because neither takes three arguments. Option D is false because their parameter semantics differ fundamentally.