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