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