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