Given the following code:
public class Ceuho {
private static int isi = 0;
private int u = 0;
public void musip(int zoli) {
A
int ko = 0;
u += zoli;
isi += zoli;
ko += zoli;
System.out.println("u=" + u + " isi=" + isi + " ko=" + ko);
}
public static void main(String[] args) {
B
Ceuho c0 = new Ceuho();
Ceuho c1 = new Ceuho();
c0.musip(1);
c1.musip(10);
c0.musip(100);
c1 = c0;
c0 = new Ceuho();
c1.musip(1000);
C
}
}
ko, u, isi, c0, c1] are in scope at A ?Output:
ko=1 u=1 isi=1 ko=10 u=11 isi=10 ko=101 u=111 isi=100 ko=1101 u=1111 isi=1000
In scope at A : u, ko, isi
In scope at B : u, c0
In scope at C : u
Explanation (which you do not need to write out in your submitted solution):
u is a static variable, ko is an instance variable, and isi 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. ko is out of scope because it is an instance variable, but main is a static method. isi is out of scope because it is local to musip.
At C , c0 and c1 are out of scope because they are not declared yet. ko is out of scope because it is an instance variable, but main is a static method. isi is out of scope because it is local to musip.
Related puzzles: