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