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