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