[英]Copy constructor is generating an error when I try to call the super constructor
為我的 class 編寫復制構造函數時,我收到一條錯誤消息,我做錯了什么?
public class SaleItem extends Item {
double price;
double shippingCost;
int numItems;
public SaleItem(SaleItem toCopy){
this.price = toCopy.price;
this.shippingCost = toCopy.shippingCost;
this.numItems = toCopy.numItems;
}
public SaleItem(String name, String description, double price, double shippingCost, int numItems){
super(name, description);
this.price = price;
this.shippingCost= shippingCost;
this.numItems = numItems;
}
您應該將該屬性聲明為protected
,例如:
public class Item {
protected String description;
protected String name;
public Item(){}
public Item(String description, String name){
this.description = description;
this.name = name;
}
//Getter and setters...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.