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