[Solved] How do you change the contents of an object in JAVA? [closed]


this.name = other.name;

I think that should work.

Update:

I forgot you want to swap their names, so:

String aux = this.name;
this.name = other.getName();
other.setName(aux);

You will need a setName and getName methods since “name” is private.

5

solved How do you change the contents of an object in JAVA? [closed]