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