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