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