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