Page 1 of 1

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

Posted: Mon Feb 18, 2013 10:42 pm
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 ..."?

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

Posted: Tue Feb 19, 2013 9:07 pm
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.

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

Posted: Sun Jul 13, 2014 3:37 am
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.

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

Posted: Sun Jul 13, 2014 7:16 am
by admin
Did you read the explanation? It explains exactly what invariant means.

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

Posted: Fri Mar 19, 2021 5:26 am
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?

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

Posted: Fri Mar 19, 2021 6:11 am
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.

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

Posted: Sat Feb 03, 2024 2:44 pm
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.

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

Posted: Sat Feb 03, 2024 7:34 pm
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.

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

Posted: Sat Apr 27, 2024 8:00 pm
by likejudo
I really don't understand this question.
If you remove base, height, area, then you must remove everything that references them and now you have nothing left.
You have an empty class.

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

Posted: Sun Apr 28, 2024 4:21 am
by admin
Why do you think you need to remove base, height and area?

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

Posted: Sun Apr 28, 2024 8:11 am
by likejudo
admin wrote:
Sun Apr 28, 2024 4:21 am
Why do you think you need to remove base, height and area?
The correct answers were to remove all of those fields.

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

Posted: Sun Apr 28, 2024 9:42 am
by admin
No, please read the problem statement carefully.

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

Posted: Sun Apr 28, 2024 11:37 am
by likejudo
admin wrote:
Sun Apr 28, 2024 9:42 am
No, please read the problem statement carefully.
It was in Unique Test #2.
I cannot find it.

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

Posted: Mon Apr 29, 2024 7:37 am
by admin
It is just asking to remove the public modifier not the whole field!!
You can press Control+Q and enter 2.901 to open the question directly.