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