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