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