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