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