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