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