You can either implement the copy constructor, for example
public Foo (Foo foo) { this.x = foo.getX(); this.y = foo.getY(); this.z = foo.getZ(); }
and then create a new copy of Foo as
Foo foo2 = new Foo(foo1);
Or you can use foo to clone and define clone() as
public Foo clone() { return new Foo(this.x, this.y, this.z); }
and then create a copy using clone() as
Foo foo2 = foo1.clone();
Please note that you can skip the definition of clone() (here), because by default the implementation of Object.clone() will execute a shallow copy and will work with the simple fields that you have.
source share