Java变量设置(如何工作?)

时间:2016-09-27 20:49:13

标签: java variables

请考虑以下代码:

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);
  }
}

在方法F2内,将o2.room设置为63后,o1.roomo2.room不应该变为63吗?为什么打印仍然为commonOffice提供275?

0 个答案:

没有答案