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