Given the following code:
public class Isriont {
private int li = 0;
public void dreme(int te) {
int i = 0;
A
i += te;
li += te;
ur += te;
System.out.println("i=" + i + " li=" + li + " ur=" + ur);
}
public static void main(String[] args) {
Isriont i0 = new Isriont();
B
Isriont i1 = new Isriont();
i0.dreme(1);
i0 = new Isriont();
i1 = new Isriont();
i1.dreme(10);
i0.dreme(100);
i1.dreme(1000);
C
}
private static int ur = 0;
}
ur, i, li, i0, i1] are in scope at A ?Output:
ur=1 i=1 li=1 ur=10 i=10 li=11 ur=100 i=100 li=111 ur=1000 i=1010 li=1111
In scope at A : li, i, ur
In scope at B : li, i0, i1
In scope at C : li
Explanation (which you do not need to write out in your submitted solution):
li is a static variable, i is an instance variable, and ur is a local variable.
At A , i0 and i1 out of scope because they are local to the main method.
At B , i is out of scope because it is an instance variable, but main is a static method. ur is out of scope because it is local to dreme.
At C , i0 and i1 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. ur is out of scope because it is local to dreme.
Related puzzles: