1. Multiple-Choice: Begin & End Index Behavior.
When calling substring(int beginIndex, int endIndex) on our MyString, which statement best describes how the returned substring is determined?
- It includes the characters at both beginIndex and endIndex, so the slice is inclusive on both ends.
- No. Remember, we include the character at beginIndex but exclude the character at endIndex.
- It includes the character at beginIndex but excludes the one at endIndex. If beginIndex == endIndex, the result is empty.
- Correct! This matches Java’s standard approach: the start is inclusive, the end is exclusive.
- Our substring automatically expands endIndex by +1 if beginIndex == endIndex, avoiding empty strings.
- No. If beginIndex == endIndex, we produce an empty substring.
- It always returns the entire string if beginIndex or endIndex is out of range, ignoring the invalid indices.
- No. We return an empty string and print an error message for invalid indices.
