Page 1 of 1

About Question enthuware.ocpjp.v11.2.3656 :

Posted: Sun Mar 21, 2021 2:09 pm
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.

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

Posted: Sun Mar 21, 2021 10:41 pm
by admin
You are right, it should be initBuddies(ba). Fixed.

thank you for your feedback!

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

Posted: Sun Apr 11, 2021 4:12 am
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.

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

Posted: Sun Apr 11, 2021 6:44 am
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!