Dan Schmidt
Dan Schmidt

Reputation: 51

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?

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;
}

Upvotes: 1

Views: 38

Answers (1)

Villat
Villat

Reputation: 1475

You should declare that attributes as protected, for instance:

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...

}

Upvotes: 1

Related Questions