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