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