what is d difference between deep cloning and shallow
cloning in core java?

Answers were Sorted based on User's Feedback



what is d difference between deep cloning and shallow cloning in core java?..

Answer / sunny

Deep cloning - You clone the object and their constituent parts.

This kind of cloning is adequated when the parts of the
object make up the object, and can not be separated from it.

A car HAS four wheels, and to clone (copy) a car, I must
clone their four wheels.

Shallow cloning - You clone only the object, not their
parts. You add references to their parts.

This kind of cloning is adequated when the parts of the
object are independent of it.

An entry in an address book has the street name, the city
name. To clone that entry, you simply add references to the
street and city names.

That distinction is a little difficult to be done in Java,
but is better understood if you think in terms of databases.

You need deep cloning if the entity requires "cascade
deleting" to be deleted. You need shallow cloning if
"cascade deleting" is not needed.

Is This Answer Correct ?    28 Yes 2 No

what is d difference between deep cloning and shallow cloning in core java?..

Answer / laxmikanth

In Shallow Cloning, you can only create the replica of the
objects but not the objects it is holding. Assume your Car
class (car1) has car name and Engine obj reference (has a
relation). Then by Shallow clone you can create anothr Car
Object (car2)but the newly created object will have its own
car name but the Engine Obj reference of car2 will still
point to car1's Engine.

In Deep Cloning, you can create the complete replica of car1
object.

Is This Answer Correct ?    4 Yes 1 No

what is d difference between deep cloning and shallow cloning in core java?..

Answer / nishant

Deep cloning - You clone the object and their constituent
parts.

Shallow cloning - You clone only the object, not their
parts. You add references to their parts

Is This Answer Correct ?    10 Yes 9 No

Post New Answer

More Core Java Interview Questions

Define Multiprogramming and Multiprocessing in java.

0 Answers   Akamai Technologies,


What is the current version of java?

0 Answers  


10. What is the output of the following Java program? class Main { public static void main(String args[]){ final int i; i = 10; System.out.println(i); } } 10. What is the output of the following Java program? class Main { public static void main(String args[]){ final int i; i = 10; System.out.println(i); } }

0 Answers  


How you can force the garbage collection?

0 Answers  


what is ststic with example

0 Answers   Wipro,






What is protected access modifier?

0 Answers  


What we have to do, when we don't want to implement all methods of an interface?

5 Answers  


What does provide mean construction?

0 Answers  


What is a method vs function?

0 Answers  


What is lazy activation?

2 Answers   CMC,


What is ascii format?

0 Answers  


What is meant by the value of a variable?

0 Answers  


Categories