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