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