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