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