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