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