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