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