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