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