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