嘿家伙,我正在尝试使用构造函数来接受大量变量,然后将相关信息传递给超类构造函数。
我得到的错误是,当我使用 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";
}
如您所见,我调用了超类propertiesale 来获取变量。
超类——
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;
}
还有更多额外的构造函数,但我相信它们现在无关紧要。