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