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