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