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