[英]Copy constructor is generating an error when I try to call the super constructor
When writing the copy constructor for my class I get an error message, what am I doing wrong?为我的 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;
}
You should declare that attributes as protected
, for instance:您应该将该属性声明为
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.