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