About Question enthuware.ocajp.i.v7.2.901 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.901 :
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 ..."?
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 ..."?
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
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.
-
- Posts: 23
- Joined: Thu May 08, 2014 5:27 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
actually i was unable to understand this question, but i answered correctly by encapsulation point of view.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
-
- Posts: 6
- Joined: Mon Mar 08, 2021 4:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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?
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?
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
-
- Posts: 5
- Joined: Tue Dec 19, 2023 12:28 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
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.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
"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.
-
- Posts: 30
- Joined: Sun Feb 18, 2024 7:21 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
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.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
Why do you think you need to remove base, height and area?
If you like our products and services, please help us by posting your review here.
-
- Posts: 30
- Joined: Sun Feb 18, 2024 7:21 pm
- Contact:
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
No, please read the problem statement carefully.
If you like our products and services, please help us by posting your review here.
-
- Posts: 30
- Joined: Sun Feb 18, 2024 7:21 pm
- Contact:
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.901 :
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.
You can press Control+Q and enter 2.901 to open the question directly.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 17 guests