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