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