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