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