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