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