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