Given the following code:
public class Prer {
private static int chod = 0;
private int cic = 0;
public void seng(int diir) {
int blon = 0;
chod += diir;
blon += diir;
cic += diir;
System.out.println("chod=" + chod + " blon=" + blon + " cic=" + cic);
A
}
public static void main(String[] args) {
B
Prer p0 = new Prer();
Prer p1 = new Prer();
p0.seng(1);
p1.seng(10);
p1 = new Prer();
p0 = p1;
p0.seng(100);
p1.seng(1000);
C
}
}
cic, chod, blon, p0, p1] are in scope at A ?Output:
cic=1 chod=1 blon=1 cic=11 chod=10 blon=10 cic=111 chod=100 blon=100 cic=1111 chod=1000 blon=1100
In scope at A : cic, blon
In scope at B : cic, p0
In scope at C : cic
Explanation (which you do not need to write out in your submitted solution):
cic is a static variable, blon is an instance variable, and chod is a local variable.
At A , chod 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 , p1 is out of scope because it is not declared yet. blon is out of scope because it is an instance variable, but main is a static method. chod is out of scope because it is local to seng.
At C , p0 and p1 are out of scope because they are not declared yet. blon is out of scope because it is an instance variable, but main is a static method. chod is out of scope because it is local to seng.
Related puzzles: