public class Car implements Cloneable{

private String name;
private int price;

Car(String name, int price)
{
    this.name = name;
    this.price = price;
}

//copy constructor 1

Car(Car a)
{
    price = a.price;
    name = a.name;
}

clone(Car a)
{
    Car newC = Car(Car a);
}

}

Car a gives me cannot find symbol. I am trying to write a class that uses a copy constructor and a clone method, but came across an error I can't solve. I've been scratching my head for 30 minutes.

有帮助吗?

解决方案

The problem is here: Car newC = Car(Car a);

That line should be: Car newC = new Car(a);

其他提示

You need to specify a return type, and the new keyword.

public Object clone(Car a) {
   Car newC = new Car(a);
   return newC;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top