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