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