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