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