About Question enthuware.ocpjp.v11.2.3656 :
Moderator: admin
-
- Posts: 1
- Joined: Sun Mar 21, 2021 2:05 pm
- Contact:
About Question enthuware.ocpjp.v11.2.3656 :
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.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3656 :
You are right, it should be initBuddies(ba). Fixed.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sun Apr 11, 2021 4:07 am
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3656 :
I believe there's an issue with the explanation for this question
and
In the explanation is states:
Code: Select all
ba[0] = ba[1]; //3
ba[1] = ba[2]; //4
Code: Select all
Buddy[] ba = new Buddy[3]
4. At //4, ba[2] is set to ba[3] but ba[3] is null. Therefore, ba[1] is also null after this line.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3656 :
You are right. It should be:
thank you for your feedback!
Fixed.
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.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: pavvel and 116 guests