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