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