Object Reference Mutation
An object is passed as a parameter to a method, allowing the method to change the internal state of the original object.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
Data d = new Data();
d.val = 5;
modify(d);
System.out.print(d.val);
}
public static void modify(Data obj) {
obj.val = obj.val * 3;
}
}
class Data {
public int val;
}
A
3
B
5
C
8
D
15
Question Leaderboard
Not enough data yet to show leaderboard.
