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