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