public Auto (Auto y) {
?
}
"uses the same name " < "name" is definitely the wrong word
The constructor is getting passed a parameter whose Type
is the same as the Class.
It is probably a copy constructor. The object being created will probably
be a copy of the object being passed in.
That's not the same name, that's the same type. So if we have "Auto y", Auto is the type and y is the name of the parameter. Anyway, these constructors are generally used to make a copy of that other object. It simply sets its own variables to the values of the variables in the other Auto object.
So for example:
public class Auto {
private int wheels;
public Auto(int wheels) {
this.wheels = wheels;
}
public Auto(Auto y) {
this.wheels = y.getWheels();
}
public int getWheels() {
return wheels;
}
}
Now I can do:
Auto firstAuto = new Auto(4);
Auto secondAuto = new Auto(firstAuto);
// both of them have 4 wheels