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