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