What is difference between shallow copy and deep copy? Which is default?



What is difference between shallow copy and deep copy? Which is default?..

Answer / hrpynux@gmail.com

Default version of clone method creates the shallow copy of an object. To create the deep copy of an object, you have to override clone method. Shallow copy is preferred if an object has only primitive fields. Deep copy is preferred if an object has references to other objects as fields.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Do the names of parameters have to agree in the prototype, definition, and call to the function?

0 Answers  


class Foo { const int x; protected: Foo(int f); ~Foo(); }; Foo f; Referring to the sample code above, why will the class declaration not compile? a) The variable x is const. b) The destructor is protected. c) The destructor is not public. d) The constructor is protected. e) There is no default constructor.

5 Answers   Quark,


What are structures and unions?

0 Answers  


write a c++ program to create class student having datamember name,Roll_no,age,and branch intilcization all the member using constructor print the all the details on the screen.

0 Answers  


What are the benefits of c++?

0 Answers  






What is the syntax for a for loop?

0 Answers  


Can you use the function fprintf() to display the output on the screen?

0 Answers  


What are the methods of exporting a function from a dll?

0 Answers  


What is the output of the following 3D Array int arr[3][2][2]={1,2,3,4,5,6,7,8,9,10,11,12}; what is the output for arr[2][1][0]?

6 Answers   HCL, Integra, IPMC, ORG,


Why do we need runtime polymorphism in c++?

0 Answers  


if there is binary tree which one is the easiest way to delete all child node?

1 Answers   Persistent,


What is guard code in c++?

0 Answers  


Categories