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