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