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