嗨,大家好,我正在尝试使用构造函数来接受大量变量,然后将相关信息传递给超类构造函数。
我遇到的错误是,当我使用this.variable时,它告诉我在类中创建该变量,但我认为调用super可以让我以这种方式使用它。
public class AuctionSale extends PropertySale {
private String highestBidder;
public AuctionSale(String saleID, String propertyAddress, int reservePrice, String highestBidder) {
super(saleID, propertyAddress, reservePrice);
this.saleID = saleID;
this.propertyAddress = propertyAddress;
this.reservePrice = reservePrice;
this.highestBidder = "NO BIDS PLACED";
}
正如你所看到的,我调用了超类propertysale来获取变量。
超类 -
public class PropertySale {
// Instance Variables
private String saleID;
private String propertyAddress;
private int reservePrice;
private int currentOffer;
private boolean saleStatus = true;
public PropertySale(String saleID, String propertyAddress, int reservePrice) {
this.saleID = saleID;
this.propertyAddress = propertyAddress;
this.reservePrice = reservePrice;
}
还有很多其他的构造函数,但我认为它们现在并不重要。