exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 24 discussion

Actual exam question from Oracle's 1z0-819
Question #: 24
Topic #: 1
[All 1z0-819 Questions]

Given:

It is required that if p instanceof Pair then p.isValid() returns true.
Which is the smallest set of visibility changes to insure this requirement is met?

  • A. left, right, setLeft, and setRight must be private.
  • B. setLeft and setRight must be protected.
  • C. left and right must be private.
  • D. isValid must be public.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ASPushkin
3 weeks, 6 days ago
Selected Answer: A
The set() method must be called without an exception. And it has to be the only place. setLeft(), setRight(), left, right must be private
upvoted 1 times
...
ASPushkin
4 months, 1 week ago
Selected Answer: C
To satisfy the requirement, the met() method must be called without an exception. When calling setLeft(), setRight() no validator checks are performed. It is necessary to exclude the possibility of calling these methods. It could be done by changing access to those methods to private.
upvoted 1 times
...
d7bb0b2
1 year, 1 month ago
The option A. "left, right, setLeft, and setRight must be private" is the correct one to ensure that if p is an instance of Pair, then p.isValid() always returns true. This is because if the fields left and right and the methods setLeft and setRight are private, then they cannot be accessed or modified outside of the Pair class. This means that the only way to modify the left and right fields is through the set method, which already checks the biFunction condition before setting the values of left and right. If the biFunction condition is not met, the set method throws an IllegalArgumentException, so it is not possible to create a Pair instance that is not valid.
upvoted 1 times
...
Stavok
1 year, 6 months ago
Selected Answer: C
The correct answer is C. left and right must be private. This is because the requirement states that if p is an instance of Pair, then p.isValid() must return true. To ensure this, the left and right fields must be private so that they can only be modified by the setLeft and setRight methods, which in turn call the validator function to check if the new values are valid before setting them. This ensures that the isValid method always returns true.
upvoted 1 times
Lebannin
1 year, 5 months ago
setLeft and setRight don't really call the validatio though
upvoted 1 times
...
...
Matt_G
1 year, 6 months ago
Selected Answer: A
All methods of changing left and right must be private or a user in the same package could put it into a state where the validator returns false
upvoted 4 times
...
Mukes877
1 year, 7 months ago
Selected Answer: C
minimal changes will be : C. left and right must be private.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago