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