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