Given the following code:
public class NinIdwe {
private static int flen = 0;
private int me = 0;
public static void main(String[] args) {
NinIdwe n0 = new NinIdwe();
A
NinIdwe n1 = new NinIdwe();
B
n0.emas(1);
n1.emas(10);
n0 = new NinIdwe();
n1 = n0;
n0.emas(100);
n1.emas(1000);
}
public void emas(int wu) {
int ii = 0;
flen += wu;
ii += wu;
me += wu;
System.out.println("flen=" + flen + " ii=" + ii + " me=" + me);
C
}
}
me, flen, ii, n0, n1] are in scope at A ?Output:
me=1 flen=1 ii=1 me=11 flen=10 ii=10 me=111 flen=100 ii=100 me=1111 flen=1000 ii=1100
In scope at A : me, n0, n1
In scope at B : me, n0, n1
In scope at C : me, ii
Explanation (which you do not need to write out in your submitted solution):
me is a static variable, ii is an instance variable, and flen is a local variable.
At A , ii is out of scope because it is an instance variable, but main is a static method. flen is out of scope because it is local to emas.
At B , ii is out of scope because it is an instance variable, but main is a static method. flen is out of scope because it is local to emas.
At C , flen 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: