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