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