public static void inc(int x) {
x = x + 1;
}
// caller: int n = 5; inc(n); System.out.println(n);What is printed and why?
- A
Compile error
- B
6; n is incremented in place
- C
0; n is reset
- Dcheck_circle
5; primitives are passed by value, so the caller's n is unchanged
Explanation
Java passes primitives by value. inc receives a copy; modifying x does not affect n in the caller.