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


Please Help Members By Posting Answers For Below Questions

What is set in java?

532


What is merge sort in java?

589


What environment variables do I need to set on my machine in order to be able to run java programs?

609


What is regex in java?

531


What is java algorithm?

525






Can a constructor have different name than a class name in java?

606


Give me an example of array and linked list? Where they can be used?

561


What is the difference between stringbuffer and stringbuilder class?

580


What is the default size of set in java?

506


why doesn't java run on all platforms?

577


Is it safe to install java on my computer?

546


What is a databasemetadata?

557


What is overriding in java?

531


What causes memory leaks in java?

498


What is an empty class? What functionality does it offer in Java?

679