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