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