Answer:
The program will throw a NullPointerException (and usually stop running).
Versions of substring()
There are two versions of substring:
substring( int from ) |
Create a new object that contains the characters of the method's string
from index from to the end of the string. |
Throws an IndexOutOfBoundsException if from is negative
or larger than the length of the string. |
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
if from is larger than to. |
There are some tricky rules about the first version of the method:
- If
fromis exactly equal to the length of the original string, a substring is created, but it contains no characters (it is an empty string) - If
fromis greather than the length of the original string, or a negative value, aIndexOutOfBoundsExceptionis thrown (and for now, your program crashes).
QUESTION 5:
What do the following statements create?