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