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