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