What is the output of the following code?
public static void main(String args[]) { String s = "string 1"; int i = 5;//from w w w. j a v a 2 s .com someMethod1(i); System.out.println(i); someMethod2(s); System.out.println(s); } public static void someMethod1(int i) { System.out.println(++i); } public static void someMethod2(String s) { s = "string 2"; System.out.println(s); }
d
The i variable in the main is not modified, as it is passed by value.
While the string is passed by reference, the local variable s was modified in the third method, not the one in the main method.