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