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