Shared Reference
Two variables refer to the same object instance. Changes made via one reference affect the object state observed by the other.
What is printed when the following Java program is compiled and run?
class Counter {
int count;
Counter(int c) {
count = c;
}
}
public class QuestionTrace {
public static void main(String[] args) {
Counter c1 = new Counter(10);
Counter c2 = c1;
c2.count += 5;
System.out.println(c1.count);
}
}
A
0
B
15
C
5
D
10
Question Leaderboard
Not enough data yet to show leaderboard.
