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