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

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

Moderator: admin

Post Reply
sergey89
Posts: 1
Joined: Wed Jul 10, 2013 6:14 am
Contact:

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

Post by sergey89 »

Good day, everyone!

Given:

class Triangle{
public int base;
public int height;
public double area = 0;

public Triangle(int base, int height){
this.base = base; this.height = height;
updateArea();
}
public void updateArea(){
double a = base*height/2;
area = a;
}
public void setBase(int b){ base = b; updateArea(); }
public void setHeight(int h){ height = h; updateArea(); }
}
Which variables are not accessible at class level?

According to explanation:
"class level" means static fields and they can be accessed from anywhere (i.e. static as well as non-static methods) in the class (and from outside the class depending on their accessibility).

But this class has no static fields, which means, that there are no variables accessible at class level at all in this class, which leads us to a conclusion, that all options are correct, am i right?

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

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

Post by admin »

The question asks about the given code. In the given code there is no static method or block. So the instance fields are accessible everywhere in the given code. Yes, if there were a static method then they would be accessible in those methods.

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

deniscapeto
Posts: 6
Joined: Wed Dec 02, 2015 5:50 pm
Contact:

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

Post by deniscapeto »

what about the constructor parameters pBase and pHeight ?
Couldn´t it be considered variables?

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

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

Post by admin »

Yes, they are variables as well and are accessible only within the constructor.
If you like our products and services, please help us by posting your review here.

adribo
Posts: 1
Joined: Fri Dec 08, 2017 6:04 am
Contact:

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

Post by adribo »

So, shouldn't the correct answer include pBase and pHeight and be like the following?
- b, h, a, pBase, pHeight

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

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

Post by admin »

adribo wrote:So, shouldn't the correct answer include pBase and pHeight and be like the following?
- b, h, a, pBase, pHeight
Not necessarily. The options don't claim to include all such variables. Also, there is no option that says, "none of the above" or something like that. That means, the question doesn't want you to think about the variables pBase and pHeight. You need to select the best option among the ones that are given.

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

leonardofaria00
Posts: 3
Joined: Fri Aug 09, 2019 11:21 am
Contact:

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

Post by leonardofaria00 »

And if so, what would be the right answer?

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests