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