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