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