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.

user2089523
  • 63
  • 2
  • 8
  • what Do you want to return in `clone` method? your method syntax is incorrect too. you have not mentioned the return type in declaration of your method. – Vishal K Mar 29 '13 at 22:39

2 Answers2

2

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

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

Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151
1

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

public Object clone(Car a) {
   Car newC = new Car(a);
   return newC;
}
Matt Wolfe
  • 8,924
  • 8
  • 60
  • 77