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