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