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 are the states of thread in java?

517


What is a class reference?

555


Why is java called java?

543


What is character in data type?

553


How do you compare two strings lexicographically?

540






What is backdrop?

596


What are 4 pillers of object orinted programming?

582


What is a boolean used for?

591


Why string is called as immutable?

524


How is a variable stored in memory?

531


How many characters is 16 bytes?

544


What is sorting in java?

536


What is a java lambda expression?

558


Why is the type for real numbers called double?

545


What is the simpletimezone class in java programming?

538