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