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