Given the following code:
public class Enem {
private int pren = 0;
public void tiss(int mo) {
int id = 0;
A
pren += mo;
me += mo;
id += mo;
System.out.println("pren=" + pren + " me=" + me + " id=" + id);
}
public static void main(String[] args) {
B
Enem e0 = new Enem();
Enem e1 = new Enem();
e0.tiss(1);
e1.tiss(10);
e0.tiss(100);
e1 = e0;
e0 = new Enem();
e1.tiss(1000);
C
}
private static int me = 0;
}
id, pren, me, e0, e1] are in scope at A ?Output:
id=1 pren=1 me=1 id=10 pren=11 me=10 id=101 pren=111 me=100 id=1101 pren=1111 me=1000
In scope at A : pren, id, me
In scope at B : pren, e0
In scope at C : pren
Explanation (which you do not need to write out in your submitted solution):
pren is a static variable, id is an instance variable, and me is a local variable.
At A , e0 and e1 out of scope because they are local to the main method.
At B , e1 is out of scope because it is not declared yet. id 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 tiss.
At C , e0 and e1 are out of scope because they are not declared yet. id 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 tiss.
Related puzzles: