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