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