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