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