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