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