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