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