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