Page 1 of 1

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

Posted: Wed Jul 10, 2013 6:21 am
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?

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

Posted: Thu Jul 11, 2013 6:28 am
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.

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

Posted: Mon Jan 04, 2016 6:40 pm
by deniscapeto
what about the constructor parameters pBase and pHeight ?
Couldn“t it be considered variables?

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

Posted: Mon Jan 04, 2016 7:49 pm
by admin
Yes, they are variables as well and are accessible only within the constructor.

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

Posted: Fri Dec 08, 2017 6:07 am
by adribo
So, shouldn't the correct answer include pBase and pHeight and be like the following?
- b, h, a, pBase, pHeight

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

Posted: Fri Dec 08, 2017 10:26 pm
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.

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

Posted: Fri Aug 09, 2019 12:04 pm
by leonardofaria00
And if so, what would be the right answer?