About Question enthuware.ocpjp.v11.2.3065 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

About Question enthuware.ocpjp.v11.2.3065 :

Post 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 :/

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

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

Post by burlacu.valeri »

Hi, I am using "OCP Java SE 11 Developer COMPLETE STUDY GUIDE".
Attachments
Fișier_001.jpg
Fișier_001.jpg (128.44 KiB) Viewed 1965 times

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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 :) )
If you like our products and services, please help us by posting your review here.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

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

Post by burlacu.valeri »

Ok, Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests