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