给出以下对象构造函数:
public class Reservation {
private int roomNum;
private int numPeople;
private int endTime;
public Reservation() {
this.roomNum = 100;
this.numPeople = 100;
}
public Reservation(int roomNum, int endTime) {
this.roomNum = roomNum;
this.numPeople = 30;
this.endTime = endTime;
}
还有物体
Reservation a = new Reservation();
Reservation c = new Reservation(309, 12);
如果我设置
a = c;
a.addTime(2) // adds number of hours to endTime
从a.endTime
到12
的{{1}}变更还是会影响14
?如果是这样,为什么?
答案 0 :(得分:1)
a =c
之后,绑定到的原始对象已丢失,将被垃圾回收。 a与c拥有相同的对象。