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