Constructor with paremeter of the same name?

for example:public Auto (String x) {model = x;}public Auto (Auto y) {?}What is the purpose of this second Constructor? I'm confused on how a constructor uses the same name in the parameter. Please help. Thank you.
[270 byte] By [kevch27a] at [2007-11-27 0:20:53]
# 1

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.

TuringPesta at 2007-7-11 22:14:00 > top of Java-index,Java Essentials,New To Java...
# 2

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

Simeona at 2007-7-11 22:14:00 > top of Java-index,Java Essentials,New To Java...