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