Given:
class Main {// ww w . j a v a 2 s .co m public int base; public int height; public double area = 0; public Main(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 from anywhere within given class code (except from where they are declared)?.
Select 1 option
Correct Option is : D
"class level" means static fields and they can be accessed from anywhere in the class.
"instance level" means the instance fields and they can be accessed only from instance methods in the class.