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