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