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