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