Clone and the Copy Constructor
Java Interview Questions for Cloning and Cloneable
(Continued from previous question...)
Clone and the Copy Constructor
For those of you who know C++, Java's clone() method is what happened to C++'s copy constructor. For those of you who don't know C++, a copy constructor is one which takes a single parameter of the same type of the class. In the body of the copy constructor, you have to copy all values from the object passed as a parameter to the object under construction. Like Java's clone() method, in a C++ copy constructor, you should allocate new memory for objects referenced (or pointed to) from instance (member) variables.
(Continued on next question...)
Other Interview Questions
|