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