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