About Question enthuware.ocajp.i.v7.2.902 :
Posted: Wed Jul 10, 2013 6:21 am
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?
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?