Given the following code:
public class Lesass {
public void odbic(int tene) {
int behi = 0;
A
osig += tene;
ti += tene;
behi += tene;
System.out.println("osig=" + osig + " ti=" + ti + " behi=" + behi);
}
private static int osig = 0;
private int ti = 0;
public static void main(String[] args) {
Lesass l0 = new Lesass();
B
Lesass l1 = new Lesass();
l0.odbic(1);
l1.odbic(10);
l0 = new Lesass();
l0.odbic(100);
l1 = l0;
l1.odbic(1000);
C
}
}
behi, osig, ti, l0, l1] are in scope at A ?Output:
behi=1 osig=1 ti=1 behi=11 osig=10 ti=10 behi=111 osig=100 ti=100 behi=1111 osig=1100 ti=1000
In scope at A : behi, osig, ti
In scope at B : behi, l0, l1
In scope at C : behi
Explanation (which you do not need to write out in your submitted solution):
behi is a static variable, osig is an instance variable, and ti is a local variable.
At A , l0 and l1 out of scope because they are local to the main method.
At B , osig 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 odbic.
At C , l0 and l1 are out of scope because they are not declared yet. osig 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 odbic.
Related puzzles: