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