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