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