About Question enthuware.ocpjp.v11.2.3656 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
enthjo
Posts: 1
Joined: Sun Mar 21, 2021 2:05 pm
Contact:

About Question enthuware.ocpjp.v11.2.3656 :

Post by enthjo »

Just ran through a test with this question and it contains an error. In this question - the method call on line //6 does not have the parameter of Buddy[] therefore it doesn't compile so the answer should be 0, not 1.

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

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

Post by admin »

You are right, it should be initBuddies(ba). Fixed.

thank you for your feedback!

Pl4cek
Posts: 1
Joined: Sun Apr 11, 2021 4:07 am
Contact:

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

Post by Pl4cek »

I believe there's an issue with the explanation for this question

Code: Select all

        ba[0] = ba[1]; //3
        ba[1] = ba[2]; //4
and

Code: Select all

Buddy[] ba = new Buddy[3]
In the explanation is states:
4. At //4, ba[2] is set to ba[3] but ba[3] is null. Therefore, ba[1] is also null after this line.

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

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

Post by admin »

You are right. It should be:

1. new Buddy[3] creates an empty array of length 3. No Buddy object is created here and each element of the array points to null.

2. One Buddy object is created at each of the lines //1 and //2.

3. At //3, ba[0] is made to point to the same object as the one pointed to by ba[1]. Therefore, nobody is now pointing to the original Buddy object pointed to by ba[0]. It is therefore eligible for GC now. However, there are two references to the second Buddy object (i.e. ba[0] as well as ba[1] are now pointing to the same Buddy object).

4. At //4, ba[1] is set to ba[2] but ba[2] is null. Therefore, ba[1] is also null after this line.

Therefore, at the end of the initBuddies method, only one Buddy object is eligible for GC.
Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests