Page 1245 - AP Computer Science A, 7th edition
P. 1245
28. (D) Suppose fullName is Dr. John Roufaiel. In segment I t he ex pres s ion fullName.indexOf(BLANK) ret urns 3. T hen temp get s as s igned t he v alue of fullName.substring(4), which is John Roufaiel. Next k gets assigned the value temp.indexOf(BLANK), nam ely 4, and firstName get s assigned temp.substring(0, 4), which is all the characters from 0 to 3 inclusive, namely John. Note that segment II works the same way, except firstName gets assigned John Roufaiel and then reassigned John. This is not good style, since a variable name should document its contents as precisely as possible. Still, the code works. Segment III fails because indexOf returns the first occurrence of its String param et er. T hus , firstBlank and secondBlank w ill bot h contain the same value, 3.