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

4

2 回答 2

2

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

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

于 2013-03-29T22:33:36.830 回答
1

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

public Object clone(Car a) {
   Car newC = new Car(a);
   return newC;
}
于 2013-03-29T22:33:44.720 回答