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