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