Page 1 of 1

About Question enthuware.ocpjp.v11.2.3065 :

Posted: Tue Mar 30, 2021 9:03 am
by burlacu.valeri
1. orig == dup will be false because dup is a clone of orig and therefore, they will point to two different array objects. Their elements, however, will point to the same objects.
3.orig[0] == dup[0] will be true because, as explained above, a clone creates a shallow copy, which means, elements of orig and dup point to the same objects.

Hi everyone, I don't understand, why (orig == dup) => false but (orig[0] == dup[0] ) => true .
In the 1 example is described what both are two different array objects. Then, is False. But in the 3 example is True :/

Re: About Question enthuware.ocpjp.v11.2.3065 :

Posted: Wed Mar 31, 2021 1:45 am
by admin
Which book are you going through?
Check out chapter 9 of Deshmukh's 1z0-815 fundamentals: https://amzn.to/2PucBeT
Specially section 9.2.2, it explains in detail what you are asking.

Re: About Question enthuware.ocpjp.v11.2.3065 :

Posted: Wed Mar 31, 2021 8:32 am
by burlacu.valeri
Hi, I am using "OCP Java SE 11 Developer COMPLETE STUDY GUIDE".

Re: About Question enthuware.ocpjp.v11.2.3065 :

Posted: Wed Mar 31, 2021 9:44 am
by admin
I don't have this book so I don't know if it explains arrays in detail. But basically, when you clone orig, a new array object is created. Thus, orig and dup point to two different array objects (so, orig == dup is false). However, the elements of the two arrays contain the same values that is why orig[0] == dup[0] is true.

You may want to google this to learn more because shallow copy is requires good understanding of how references work, which is important for any Java developer.

Or just purchase the kindle version of Deshmukh's book, which explains all the basics very clearly. it is only 2.99$ (a lot cheaper than the book you have :) )

Re: About Question enthuware.ocpjp.v11.2.3065 :

Posted: Thu Apr 01, 2021 5:59 am
by burlacu.valeri
Ok, Thanks.