Given the following code:
public class Norme {
private int uei = 0;
public static void main(String[] args) {
A
Norme n0 = new Norme();
Norme n1 = new Norme();
B
n0.bergan(1);
n1.bergan(10);
n0.bergan(100);
n0 = new Norme();
n1 = new Norme();
n1.bergan(1000);
}
private static int es = 0;
public void bergan(int joo) {
int enen = 0;
es += joo;
uei += joo;
enen += joo;
System.out.println("es=" + es + " uei=" + uei + " enen=" + enen);
C
}
}
enen, es, uei, n0, n1] are in scope at A ?Output:
enen=1 es=1 uei=1 enen=11 es=10 uei=10 enen=111 es=101 uei=100 enen=1111 es=1000 uei=1000
In scope at A : enen, n0
In scope at B : enen, n0, n1
In scope at C : enen, es
Explanation (which you do not need to write out in your submitted solution):
enen is a static variable, es is an instance variable, and uei is a local variable.
At A , n1 is out of scope because it is not declared yet. es is out of scope because it is an instance variable, but main is a static method. uei is out of scope because it is local to bergan.
At B , es is out of scope because it is an instance variable, but main is a static method. uei is out of scope because it is local to bergan.
At C , uei is out of scope because it is not declared yet. n0 and n1 out of scope because they are local to the main method.
Related puzzles: