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