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