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