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