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