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