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