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