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