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