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