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