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