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