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