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