我已经像这样设置了我的构造函数:
public class VendingMachine {
private double currentBalance;
private double itemPrice;
private double totalCollected;
public VendingMachine(double itemCost) {
currentBalance = 0;
totalCollected = 0;
itemPrice = itemCost;
}
...
}
我的问题是通过接受 double 的参数来设置我的构造函数有什么区别itemCost
。
与制作相比有什么区别:
this.itemPrice = itemCost;