public class Cell {
public int v;
}
public class Helper {
public static void replace(Cell c) {
c = new Cell();
c.v = 999;
}
}
// ...
Cell c = new Cell();
c.v = 10;
Helper.replace(c);
System.out.println(c.v);What is printed?
- A
999
- Bcheck_circle
10
- C
Compile-time error
- D
0
Explanation
Reassigning the parameter c inside replace only changes the local variable; the original reference is unchanged.