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