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