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