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