Object references are actually pointers, they store a memory address. They do not store an actual copy of the object's data. For example, this code in Java:
Object o = new Object();
System.out.println(o.toString());
is the same as this code in C++ (assuming there is an Object
class):
Object *o = new Object();
cout << o.toString();
In C++, you can pass an actual copy of the object data if you want to. This is not possible in Java, because it is more efficient to just have a pointer and not consume a lot of memory.
However, if you pass an object to a constructor (or any method), it could do whatever it wants with it, including make a copy of it (using clone
) or gather some data from it to use in constructing itself. So the constructor could make a copy, but you are not making a copy just by passing the object to a constructor.
See also: Is Java "pass-by-reference"?