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