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