Consider the following code:
public class Office {
int room;
Office(int room) {
this.room = room;
}
}
class Test {
public static void F2(Office o1, Office o2) {
o2 = o1;
o2.room = 63;
}
public static void main(String[] args) {
Office labOffice = new Office(130);
Office commonOffice = new Office(275);
F2(labOffice, commonOffice);
System.out.println(labOffice.room + ", " + commonOffice.room);
}
}
Inside method F2
, after setting o2.room
to 63, shouldn't both o1.room
and o2.room
become 63? Why does printing still give me 275 for commonOffice
?