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