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