Given the following code:
public class Talm {
public static void main(String[] args) {
Talm t0 = new Talm();
A
Talm t1 = new Talm();
B
t0.polin(1);
t0 = new Talm();
t1 = t0;
t1.polin(10);
t0.polin(100);
t1.polin(1000);
}
private static int to = 0;
private int piw = 0;
public void polin(int ar) {
int is = 0;
piw += ar;
to += ar;
is += ar;
System.out.println("piw=" + piw + " to=" + to + " is=" + is);
C
}
}
is, piw, to, t0, t1] are in scope at A ?Output:
is=1 piw=1 to=1 is=10 piw=11 to=10 is=110 piw=111 to=100 is=1110 piw=1111 to=1000
In scope at A : piw, t0, t1
In scope at B : piw, t0, t1
In scope at C : piw, is
Explanation (which you do not need to write out in your submitted solution):
piw is a static variable, is is an instance variable, and to is a local variable.
At A , is is out of scope because it is an instance variable, but main is a static method. to is out of scope because it is local to polin.
At B , is is out of scope because it is an instance variable, but main is a static method. to is out of scope because it is local to polin.
At C , to 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: