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