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