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