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