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