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