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

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

Moderator: admin

Post Reply
admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

JeramieH wrote:
This question is virtually identical to enthuware.ocajp.i.v7.2.876, except the correct answer over there takes a totally different track.
Yes, we wanted to show the multiple ways in which you can be asked these kinds of questions in the exam. I agree that the solutions are a bit subjective (and need based) but still, keeping complexities aside, you can apply basic OO rules to arrive at an answer. Even if you don't agree with the answer, but they make you think about the issues involved and that is the goal of this question.

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

phogi.java
Posts: 3
Joined: Sun Oct 26, 2014 9:31 am
Contact:

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

Post by phogi.java »

My problem here is that I keep thinking that to successfully refactor Square, any current users should not be affected. Which means, I cannot make a public field private, because it will break any current users that are already using the class, such as TestClass which is directly using the area field (sq.area).

evaevaeva
Posts: 10
Joined: Fri Mar 06, 2020 5:18 am
Contact:

ERROR IN Question enthuware.ocajp.i.v7.2.877 :

Post by evaevaeva »

The 'right' answer says: "Add a calculateArea method:

private void calculateArea(){
this.area = this.side*this.side;
}
"
But shouldn't it be PUBLIC instead of PRIVATE?!! In other words: isn't this an error in the answer?!

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

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

Post by admin »

No, why should it be public? This functionality is used only internally within the class. The existing class does not expose this functionality outside either.
If you like our products and services, please help us by posting your review here.

evaevaeva
Posts: 10
Joined: Fri Mar 06, 2020 5:18 am
Contact:

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

Post by evaevaeva »

It should be public because it says so everywhere: 1. Declare the variables of a class as private. 2. Provide public setter and getter methods to modify and view the variables values.
That's what I have been learning all the way, so please help me understand why here they use a private a.m. I mean, you could of course, but then don't ask about 'terms of encapsulation', because it's contradictory.

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

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

Post by admin »

please read the response just above your post. It explains why calculateArea method should be private.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 32 guests