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