Q for the ranch hands out there...
I bought the new
Java 2 study guide (by Heller, Roberts), and there's a
test question provided that doesn't seem right:
What does the following code print out?
1. class Cases {
2. public static void main(
String[] args) {
3. String s = "abcde";
4. s = s.toUpperCase();
5. System.out.println(s);
6. }
7. }
a) abcde
b) ABCDE
Now, being that everyone knows that the original string IS NOT changed, I figured 'a' would be the correct answer- s is not modified, but a new string is created. However, it says 'b'....
The call on line 4 does not modify the original string; it creates a new string, and modifies s so that it points to the new string.
Why would reference s point to anything but the original string? This doesn't make sense....