About Question enthuware.ocajp.i.v7.2.901 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.901 :

Post by ETS User »

I had the following misunderstanding about the question. I thought the goal was to make the area field itself invariant. I didn't realize "invariant" was a special term, a noun and not an adjective in this case. The options I selected do protect area from public tampering (3, 5, 6), but at the cost of allowing the relationship between the height, width, and area to vary.

If the goal of the question is to test the ability to preserve the relationship, why not spell it out a little more explicitly? I think the language "an invariant on X" can easily be interpreted to mean X should not be varied. Why not say "an invariant relationship between X and other instance variables" for example? Or "the invariant between X and ..."?

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

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by admin »

The problem statement says "...an invariant on the "area" field...". It does not say that area is invariant. The reason it is specified this way is because some candidates have reported getting questions that contains this term.

It is easy to change the wordings but then we want to make sure you are aware of such confusing terms that you might see on the exam.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

kashyapa
Posts: 23
Joined: Thu May 08, 2014 5:27 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by kashyapa »

Could someone explain what does this question expect with the term of 'invariant' ?
actually i was unable to understand this question, but i answered correctly by encapsulation point of view.

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

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by admin »

Did you read the explanation? It explains exactly what invariant means.
If you like our products and services, please help us by posting your review here.

f.motta
Posts: 6
Joined: Mon Mar 08, 2021 4:13 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by f.motta »

But, we must make them private right?

Since the question talk about remove instead change, if we just remove the public modifiers than them will be package-private, making possible change their values.

What I'm missing?

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

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by admin »

Yes, but only from classes within the same package. Ideally, they should be private but you may find some ambiguity in the real exam question as well that is why we have put a question like this in our bank. You need to select the option depending on the exact wording of the problem statement. In this case, the given options are the best options.
If you like our products and services, please help us by posting your review here.

gosheymj
Posts: 5
Joined: Tue Dec 19, 2023 12:28 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by gosheymj »

In my opinion the verbiage here is unnecessarily confusing and it may be worthwhile update the verbiage to clarify what is being asked.
Most typically in computing, an "invariant" refers to a condition that must remain true, such as "the assigned value must not be negative" or "the value must be divisible by two" or other such constraint (see the Java code examples in this wiki entry: https://en.wikipedia.org/wiki/Class_invariant).
In the question above, the act of merely changing the three public fields to private access does nothing to protect any such "invariant" on the "area" field since the user is free to pass any value they like to the constructor and/or setter methods.

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

Re: About Question enthuware.ocajp.i.v7.2.901 :

Post by admin »

Sure, will improve. But your argument
"In the question above, the act of merely changing the three public fields to private access does nothing to protect any such "invariant" on the "area" field" is not correct because the condition that area must be equal to base*height/2 is the invariant here and needs to be protected. This is just like the example you quoted from wiki, "the value must be divisible by two". It doesn't mean the value is constant.


thank you for your feedback.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: admin and 94 guests