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