Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard

Question 8

Question ID: UKOCP70946


Given code:


Does above code expose internal data?

  • A Yes
  • B No
Reveal correct answer

Correct answer: A

Explanation

UKOCP70946:

Even though 'attackCoordinates' is private and final, but ArrayList object it refers is not constant.

return attackCoordinates; exposes this ArrayList object, whose contents may be changed by the calling code.


return attackCoordinates; should be written as return Collectionss.unmodifiableList(attackCoordinates);

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need