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