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