what is d difference between deep cloning and shallow
cloning in core java?
Answer Posted / 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 |
Post New Answer View All Answers
What's the difference between an abstract class and interface in java?
Can we override static methods in java?
why Java does not support multiple inheritances?
How do generics work?
How does remove work in java?
What is a map in java?
What are the legal operands of the instanceof operator?
Can one thread block the other thread?
Can we have a method name same as class name in java?
Which method you will use to create a new file to store some log data. Each time a new log entry is necessary, write string to the file in java ?
What is jit compiler ?
How can constructor chaining be done by using the super keyword?
Why declare Main() method as a static in java ?
What is a container in a gui?
How is java hashmap implemented?