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