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