Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which of the following is true? You may need to select more than one answer. (TH

ID: 3851120 • Letter: W

Question

Which of the following is true? You may need to select more than one answer. (THIS IS A QUESTION ON JAVA PROGRAMMING)

1.) When cloning an object, a deep copy and a shallow copy are the same for a primitive type.
2.) When cloning an object, a deep copy of a reference type copies the reference object's contents.
3.) When cloning an object, a shallow copy of a reference type copies the reference object's reference (address).
4.) When cloning an object, a deep copy and a shallow copy are the same for a reference type.

Explanation / Answer

Solution :

2 and 3 are true.

explanation :

- When clone function is called then :

1) in case of shallow copy, all reference object's addresses are copied. i.e new cloned object will point to the same old object. If property is primitive type then value of primitive type is copied and both have different addresses.

Hence in case of shallow copy only reference type addresses are copied and new object will point to old object.

2)In case of deep copy, all reference type object contents are being copied to other memory space and both (new and old) objects will point to the different address locations.

If you have any doubts then you can ask in comment section.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote