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