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