Content deleted Content added
Oops, deleted too much end stuff. |
m sp: a argument→an argument |
||
Line 23:
Object myObj = new Object();
</pre>
This instantiates, or creates, an object and puts it into some piece of memory in the computer, and returns a reference to the instantiated object. So the variable myObj effectively holds a reference rather than the actual object itself. This is why the code in Fig. 2 copies only the reference, and not the actual object. So the variable original and copy actually point to the same thing! The reason why this is done is for efficiency. Instead of copying the entire object to assign it to the destination variable (which the object can get very large), and instead just juggle around references (which are simply integers in C/C++), it makes the distribution of the object around in a program (eg. passing it as
This process of passing references around is called shallow copying.
|