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