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