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