What is the result of the following program?
1:public class Main { 2: public static void addToInt(int x, int v) { 3: x = x + v; //from ww w . j a v a 2 s . co m 4: } 5: public static void main(String[] args) { 6: int a = 15; 7: int b = 10; 8: Main.addToInt(a, b); 9: System.out.println(a); 10: } 11:}
B.
The code compiles successfully, so options D and E are incorrect.
The value of a cannot be changed by the addToInt()
method, no matter what the method does, because only a copy of the variable is passed into the parameter x.
Therefore, a does not change and the output on line 9 is 15.