I got this from Enthuware
Which line will print the
string "MUM"?
For line 3 the explanation given is "It will print IMUM. as s.indexOf('I', 3) will return 3."
For line 4 the explanation says "It will throw an exception as s.indexOf('I', 4) will return -1."
For line 3 the search for I starts at index 3. So it will return 3. For line 4 the search for I starts at index 4 and of course there is nothing. But why will it give an exception when the search returns -1 when no 'I' is found.
Thanks,
Meera