Answer:
Only one value is legitimate: 0 .
Two-parameter substring()
There is a second version of substring():
substring( int from, int to ) |
Create a new object that contains the characters of the method's string
from index from to index to-1. |
Throws an IndexOutOfBoundsException if from is negative
or if from is larger than to. |
Remember those tricky rules about the second version of the method:
- If
fromis negative, anIndexOutOfBoundsExceptionis thrown. - If
fromis larger thanto, anIndexOutOfBoundsExceptionis thrown. - If
tois larger than the length, anIndexOutOfBoundsExceptionis thrown. - If
fromequalsto, and both are within range, then an empty string is returned.
These rules make sense. If something can't be done, Java throws an exception.
QUESTION 7:
What do the following statements create?