Given:
public class Main { public static void main(String[] args) { String s = "JAVA"; s = s + "rocks"; s = s.substring(4,8); s.toUpperCase(); System.out.println(s); } }
What is the result?
A. JAVA B. JAVAROCKS C. rocks D. rock E. ROCKS F. ROCK G. Compilation fails
D is correct.
The substring()
invocation uses a zero-based index and the second argument is exclusive, so the character at index 8 is NOT included.
The toUpperCase()
invocation makes a new String object that is instantly lost.
The toUpperCase()
invocation does NOT affect the String referred to by s.
A, B, C, E, F, and G are incorrect based on the above.