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 is a parent class in java?
What is the scope or life time of instance variables?
Name some OOPS Concepts in Java?
What is the new line character?
Where and how can you use a private constructor?
Are there structures in java?
Can we restart a thread already started in java?
What is bubble sort in java?
What do you understand by the term wrapper classes?
Which java version is latest?
Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.
What is the this keyword?
How do you do a line break in java?
What are the steps that are followed when two computers connect through tcp?
Why do we override tostring method in java?