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