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